java – How to convert byte[] to InputStream?-ThrowExceptions

Exception or error:

Possible Duplicate:
Can we convert a byte array into an InputStream in Java?

There is a way to convert an array of bytes (byte[]) to InputStream in Java? I looked at some methods in Apache Commons IO, but found nothing.

How to solve:

ByteArrayInputStream extends InputStream:

InputStream myInputStream = new ByteArrayInputStream(myBytes); 

Answer:

Should be easy to find in the javadocs…

byte[] byteArr = new byte[] { 0xC, 0xA, 0xF, 0xE };
InputStream is = new ByteArrayInputStream(byteArr);

Answer:

ByteArrayInputStream

Answer:

Check out java.io.ByteArrayInputStream

Answer:

Theres the ByteArrayInputStream.

It does exactly this.

Answer:

How about ByteArrayInputStream?

Leave a Reply

Your email address will not be published. Required fields are marked *