ByteArrayOutputStream write Example
ByteArrayOutputStream class write example. This example shows you how to use write method.
ByteArrayOutputStream class write example. public void write(int b) Writes the specified byte to this byte array output stream.
Here is the code
/**
* @ # Write1.java
* A class reprsenting use to write method
* of ByteArrayOutputStream class in java.io package
* version 09 June 2008
* author Rose India
*/
import java.io.*;
public class Write1 {
public static void main(String args[]) throws Exception {
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
//Writes a byte to the byte array output stream.
oStream.write(1);
System.out.println("Byte of the byte array output stream");
byte b[] = oStream.toByteArray();
for (int i = 0; i < b.length; i++) {
System.out.print(b[i]);
}
}
} |
Output
Byte of the byte array output stream
1 |
|