PipedInputStream read Example
PipedInputStream class read example. This example shows you how to use read method.
PipedInputStream class read example. PipedInputSpublic int read(byte[],int ,int) throws IOException Reads up to len bytes of data from this piped input stream into an array of bytes.tream class read example.
Here is the code
/**
* @ # Read1.java
* A class repersenting use to Read method
* of PipedInputStream class in java.io package
* version 03 June 2008
* author Rose India
*/
import java.io.*;
public class Read1 {
public static void main(String args[]) throws Exception {
byte[] b = {1, 2, 3, 4, 5};
PipedOutputStream poStream = new PipedOutputStream();
PipedInputStream piStream = new PipedInputStream();
//piped input stream connect to the piped output stream
piStream.connect(poStream);
//Writes specified byte array.
poStream.write(b, 0, 5);
//Reads byte from piped input stream.
System.out.println(piStream.read(b, 0, 5));
// Closes piped input stream
poStream.close();
// Closes piped output stream
piStream.close();
}
} |
|