PipedWriter write Example
PipedWriter class write example. This example shows you how to use write method.
PipedWriter class write example.
Here is the code
/**
* @ # Writer1.java
* A class repersenting use to write method
* of PipedWriter class in java.io package
* version 30 May 2008
* author Rose India
*/
import java.io.*;
public class Writer1 {
public static void main(String args[]) throws Exception {
// Create a new instance of a PipedWriter object.
PipedWriter writer = new PipedWriter();
// Connect the PipedWriter to a PipedReader object.
PipedReader reader = new PipedReader();
writer.connect(reader);
// Read from the PipedWriter.
String s = "RoseIndia.net";
char[] arr = s.toCharArray();
writer.write(arr, 0, arr.length);
writer.flush();
while (reader.ready()) {
System.out.print((char) reader.read());
}
// Close the PipedReader and PipedWriter.
reader.close();
writer.close();
}
} |
|