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