Thursday, May 12, 2011

Read partial byte array using ByteArrayInputStream Example

We can write byte array completely as well as partially, i.e. we can write byte array from one index to other. We have already written byte array completely here. We can read byte array partially like this:

/* uses ByteArrayInputStream(byte[] b, int offset, int length)
public static void printPartialByteArray(byte[] bytes, offset, length)
ByteArrayInputStream bis = new ByteArrayInputStream(bytes, offset, length);
int ch;

while ((ch = != -1)


Using the above function:

String str = "Partial Byte Array InputStream Example";

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

No comments:

Post a Comment