How to convert byte[] to InputStream?
152,053
Solution 1
ByteArrayInputStream
extends InputStream
:
InputStream myInputStream = new ByteArrayInputStream(myBytes);
Solution 2
Should be easy to find in the javadocs...
byte[] byteArr = new byte[] { 0xC, 0xA, 0xF, 0xE };
InputStream is = new ByteArrayInputStream(byteArr);
Solution 3
Solution 4
Theres the ByteArrayInputStream.
It does exactly this.
Solution 5
Check out java.io.ByteArrayInputStream
![Renato Dinhani](https://i.stack.imgur.com/rT4xU.jpg?s=256&g=1)
Comments
-
Renato Dinhani about 2 years
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.