What type is the best to manage binary data in Java? -


i'm getting documents web , many of them binary files (executables, pdf, etc.). in java, correct type hold binary data until save in database? can use string this?

use byte array (byte[]) or inputstream (e.g. bytearrayinputstream). java strings not container generic binary data.

the apache library commons-io has nice utility classes dealing bytes , streams.

e.g. ioutils.tobytearray(inputstream)


bytebuffer introduced part of java nio, available in java 4 (1.4) , later. in specialized scenarios, can have performance benefits on using byte[]. has helpful convenience methods. still use byte[], though, since more known, more common in apis, , performs enough.


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -