PipedReader read Example
PipedReader class read example. This example shows you how to use read method.
PipedReader class read example. public int read() throws IOException Reads the next character of data from this piped stream. If no character is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.
Here is the code
/**
* @ # Read.java
* A class repersenting use to read method
* of PipedWriter class in java.io package
* version 30 May 2008
* author Rose India
*/
import java.io.*;
public class Read {
public static void main(String args[]) throws Exception {
// Create a new instance of a PipedReader object.
PipedReader reader = new PipedReader();
// Connect the PipedReader to a PipedWriter object.
PipedWriter writer = new PipedWriter();
reader.connect(writer);
// Read from the PipedWriter.
writer.write("RoseIndia.net");
while (reader.ready()) {
System.out.print((char) reader.read());
}
// Close the PipedReader and PipedWriter.
reader.close();
writer.close();
}
} |
|