Java IO Tutorial - Java FilterInputStream.available()








Syntax

FilterInputStream.available() has the following syntax.

public int available()  throws IOException

Example

In the following code shows how to use FilterInputStream.available() method.

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
//  w w w .  j  a  va2  s . c o m
public class Main {
  public static void main(String[] args) throws IOException {

    int i = 0;

    InputStream is = new FileInputStream("C://test.txt");
    FilterInputStream fis = new BufferedInputStream(is);

    while ((i = fis.read()) != -1) {
      char c = (char) i;

      System.out.print("Read: " + c);

      int  j = fis.available();

      System.out.println("; Available bytes: " + j);
    }
  }
}