OutputStreamWriter write Example
OutputStreamWriter class write example. This example shows you how to use write method.
OutputStreamWriter class write example. public void write(int c) throws IOException Writes a single character.
Here is the code
/**
* @ # Write1.java
* A class repersenting use to write method
* of OutputStreamWriter class in java.io package
* version 03 June 2008
* author Rose India
*/
import java.io.*;
public class Write1 {
public static void main(String args[]) throws Exception {
// Create a new instance of a OutputStreamWriter object
// attached to a ByteArrayOutputStream.
ByteArrayOutputStream out =
new ByteArrayOutputStream();
OutputStreamWriter writer = new OutputStreamWriter(out);
// Write to the output stream.
String s = "Random bytes";
for (int i = 0; i < s.length(); i++) {
writer.write(s.charAt(i));
}
writer.flush();
// Display the contents of the ByteArrayOutputStream.
System.out.println(out.toString());
// Close the OutputStreamWriter object.
writer.close();
}
} |
|