Java IO Tutorial - Java LineNumberInputStream .available ()








Syntax

LineNumberInputStream.available() has the following syntax.

public int available()  throws IOException

Example

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

/*from  w  ww  .j  a va  2  s  . c o  m*/

import java.io.FileInputStream;
import java.io.IOException;
import java.io.LineNumberInputStream;

public class Main {
  public static void main(String[] args) throws IOException {


    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);
    int i;
    while ((i = lnis.read()) != -1) {

      char c = (char) i;

      System.out.println("Character read: " + c);

      int j = lnis.available();

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

  }
}