Java ByteArrayOutputStream .toByteArray ()
Syntax
ByteArrayOutputStream.toByteArray() has the following syntax.
public byte[] toByteArray()
Example
In the following code shows how to use ByteArrayOutputStream.toByteArray() method.
/*from ww w. j ava 2s . c o m*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
byte[] bs = { 65, 66, 67, 68, 69 };
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(bs);
for (byte b : baos.toByteArray()) {
baos.write(b);
System.out.println(b);
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »