InputStream Read1() Example
Reads up to len bytes of data from the input stream into an array of bytes.
InputStreamclass Read1() method example. This example shows you how to use Read1() method.This method Reads up to len bytes of data from the input stream into an array of bytes.
Here is the code:-
/**
* @Program that Reads up to len bytes of data from the input stream into an
* array of bytes.
* Read1.java
* Author:-RoseIndia Team
* Date:-06-Jun-2008
*/
import java.io.*;
public class Read1 extends InputStream {
public int read() throws IOException {
return 0;
}
public static void main(String[] args) throws IOException {
PipedInputStream i = new PipedInputStream();
PipedOutputStream o = new PipedOutputStream();
i.connect(o);
byte[] b = {1, 2, 3, 4, 5};
o.write(b);
System.out.print("The estimate of the number of bytes that can be read : ");
while (i.available() != 0) {
//Reads up to len bytes of data from the input stream into an array of bytes.
System.out.print(" " + i.read(b,1,b.length-1));
}
i.close();
}
} |
Output of the Program
| The estimate of the number of bytes that can be read : 4 1 |
|