Thursday, May 12, 2011

Read byte array using ByteArrayInputStream Example

Here we read the byte array and put it on console.

Function to read the byte array:

public static void readByteArray(byte[] bytes){
ByteArrayInputStream bai = new ByteArrayInputStream(bytes);

int ch;

//read bytes from ByteArrayInputStream using read method
while((ch = != -1)


Using the above function:

String str = "ByteArrayInputStream Example!";

//get bytes from string using getBytes method
byte[] bytes = str.getBytes();

For partial reading of byte array read here.

No comments:

Post a Comment