Rabu, 28 Juli 2021

How to Convert Byte Array to InputStream and OutputStream in Java? Example

Are you stuck with your coding because you have a byte array and the next method in the chain needs an InputStream? don't worry Java has a solution for that, You can use ByteArrayInputStream to convert byte array to InputStream in Java. This class takes a byte array as the source and since it's a subclass of InputStream, you can easily pass this to any method, which accepts InputStream as a parameter. Though most of the API like JDBC and File API allows you to read directly from InputStream because this allows you to process an arbitrary content with limited heap space. You should take advantage of this and directly read from InputStream instead of getting byte array and then converting them back to InputStream.

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

Comments


EmoticonEmoticon