Rabu, 28 Juli 2021

How to Convert InputStream to Byte Array in Java - 2 Examples

Sometimes we need to convert InputStream to byte array in Java, or you can say reading InputStream as a byte array, In order to pass output to a method that accepts byte array rather than InputStream. One popular example of this, I have seen is an older version of Apache commons-codec, while converting byte array to the hex string. Though, a later version of the same library does provide an overloaded method, to accept InputStream. Java File API provides excellent support to read files like image, text as InputStream in Java program, but as I said, sometimes you need String or byte array, instead of InputStream .

Lorem ipsum is simply dummy text of the printing and typesetting industry.

Comments


EmoticonEmoticon