Java InputStream.available()
Syntax
InputStream.available() has the following syntax.
public int available() throws IOException
Example
In the following code shows how to use InputStream.available() method.
/*from w w w . j a va 2s . c om*/
import java.io.FileInputStream;
import java.io.InputStream;
public class Main {
public static void main(String[] args) throws Exception {
int i = 0;
// new input stream created
InputStream is = new FileInputStream("C://test.txt");
// read till the end of the stream
while ((i = is.read()) != -1) {
// convert integer to character
char c = (char) i;
// print
System.out.println("Character Read: " + c);
}
is.close();
}
}
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »