PipedReader read Example

PipedReader class read example. This example shows you how to use read method.


PipedReader class read example.public int read(char[] cbuf, int, int) throws IOException Reads up to len characters of data from this piped stream into an array of characters. Less than len characters will be read if the end of the data stream is reached or if len exceeds the pipe's buffer size. This method blocks until at least one character of input is available.

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 Read1 {

    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.
        String s = "RoseIndia.net";
        writer.write(s);

        char[] arr = new char[s.length()];
        while (reader.ready()) {
            reader.read(arr, 0, arr.length);
            System.out.print(arr);
        }

        // Close the PipedReader and PipedWriter.
        reader.close();
        writer.close();
    }
}

Output
RoseIndia.net

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US