OutputStreamWriter write Example
OutputStreamWriter class write example. This example shows you how to use write method.
OutputStreamWriter class write example. public void write(String str, int , int ) throws IOException Writes a portion of a string.
Here is the code
/**
* @ # Write2.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 Write2 {
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";
// Only write from the 7th character on.
writer.write(s, 7, s.length() - 7);
writer.flush();
// Display the contents of the ByteArrayOutputStream.
System.out.println(out.toString());
// Close the OutputStreamWriter object.
writer.close();
}
} |
|