PipedWriter connect(PipedReader) in Java

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

Syntax:

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

This method takes one argument. This method connects this piped writer to a receiver. If this object is already connected to some other piped reader, an IOException is thrown.

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

src.connect(snk) or the call: snk.connect(src).

The two calls have the same effect.

Parameters: One parameter is required for this method.

snk: the piped reader 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 PipedWriterconnect {
    public static void main(String[] args) throws IOException {

        PipedWriter pipedWriter = new PipedWriter();

        PipedReader snk = new PipedReader();
        pipedWriter.connect(snk);

        System.out.println("Connecting the piped write");
        pipedWriter.close();

    }
}

Output:

Connecting the piped write


Some other methods of PipedWriter

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

connect(PipedReader)This method connects this piped writer to a receiver.

flush()This method flushes this output stream and forces any buffered output characters to be written out.

PipedWriter(): This method creates a piped writer that is not yet connected to a piped reader.

PipedWriter(PipedReader)This method creates a piped writer connected to the specified piped reader.

write(int)This method writes the specified char to the piped output stream.

write(char[], int, int)This method writes len characters from the specified character array starting at offset off to this piped output stream.

No comments:

Post a Comment