Java PipedOutputStream .connect (PipedInputStream snk)
Syntax
PipedOutputStream.connect(PipedInputStream snk) has the following syntax.
public void connect(PipedInputStream snk) throws IOException
Example
In the following code shows how to use PipedOutputStream.connect(PipedInputStream snk) method.
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
// w w w .j a v a 2 s .c o m
public class Main extends PipedInputStream {
public static void main(String[] args) throws Exception {
PipedOutputStream out = new PipedOutputStream();
Main in = new Main();
// connect input and output
out.connect(in);
// write something
out.write(70);
out.write(71);
// print what we wrote
for (int i = 0; i < 2; i++) {
System.out.println("" + (char) in.read());
}
out.close();
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »