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