How to convert Byte array to ByteArrayOutputStream

Arun picture Arun · Sep 2, 2013 · Viewed 51.7k times · Source

I need to convert a byte array to ByteArrayOutputStream so that I can display it on screen.

Answer

Josh M picture Josh M · Sep 2, 2013
byte[] bytes = ....;
ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length);
baos.write(bytes, 0, bytes.length);

Method description:

Writes len bytes from the specified byte array starting at offset off to this byte array output stream.