PipedReader connect(PipedWriter) in Java

connect(PipedWriter): This method is available in the java.io.PipedReader class of Java.

Syntax:

void java.io.PipedReader.connect(PipedWriter src) throws IOException

This method takes one argument. This method causes this piped reader to be

connected to the piped writer src. If this object is already connected to someother piped writer, an IOException is thrown.

If src is an unconnected piped writer and snk is an unconnected piped reader, they may be connected by either the call: snk.connect(src) or the call: src.connect(snk)

The two calls have the same effect.

Parameters: One parameter is required for this method.

src: The piped writer to connect to.

Returns: NA

Throws:

IOException - if an I/O error occurs.

Approach

Java

import java.io.IOException;
import java.io.PipedReader;
import java.io.PipedWriter;

public class PipedReaderconnect {
    public static void main(String[] args) throws IOException {

        PipedReader pipedReader = new PipedReader();

        PipedWriter src = new PipedWriter();
        pipedReader.connect(src);
        System.out.println("Connecting the piped reader");
        pipedReader.close();

    }
}

Output:

Connecting the piped reader


Some other methods of PipedReader

close()This method Closes this piped stream and releases any system resources associated with the stream.

connect(PipedWriter)This method causes this piped reader to be connected to the piped writer src.

PipedReader()This method creates a PipedReader so that it is not yet connected. It must be connected to a PipedWriter before being used.

PipedReader(int) This method creates a PipedReader so that it is not yet connected and uses a specified pipe size for the pipe's buffer.

PipedReader(PipedWriter)This method creates a PipedReader so that it is connected to the piped writer src.

PipedReader(PipedWriter, int)This method creates a PipedReader so that it is connected to the piped writer src and uses the specified pipe size for the pipe's buffer.

read()This method reads the next character of data from this piped stream.

read(char[], int, int)This method reads up to len characters of data from this piped stream into an array of characters.

ready()This method tells whether this stream is ready to be read.

No comments:

Post a Comment