PipedWriter write Example
PipedWriter class write example. This example shows you how to use write method.
PipedWriter class write example.public void write(char[] cbuf, int off, int len) throws IOException Writes len characters from the specified character array starting at offset off to this piped output stream. This method blocks until all the characters are written to the output stream. If a thread was reading data characters from the connected piped input stream, but the thread is no longer alive, then an IOException is thrown.
Here is the code
/**
* @ # Write.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 Write {
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();
}
} |
|