PipedWriter connect Example
PipedWriter class connect example. This example shows you how to use connect method.
PipedWriter class connect example. public void connect(PipedReader snk) throws IOException Connects this piped writer to a receiver. If this object is already connected to some other piped reader, an IOException is thrown.
Here is the code
/**
* @ # Connect.java
* A class repersenting use to connect method
* of PipedWriter class in java.io package
* version 30 May 2008
* author Rose India
*/
import java.io.*;
public class Connect {
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.
writer.write("RoseIndia.net");
writer.flush();
while (reader.ready()) {
System.out.print((char) reader.read());
}
// Close the PipedReader and PipedWriter.
reader.close();
writer.close();
}
} |
|