Java LineNumberInputStream .getLineNumber ()

Syntax

LineNumberInputStream.getLineNumber() has the following syntax.

public int getLineNumber()

Example

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


/*from  ww  w .j a  v a  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 {

    int i;
    FileInputStream fis = new FileInputStream("C:/test.txt");
    LineNumberInputStream lnis = new LineNumberInputStream(fis);

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

      if (i != 10) {
        System.out.println("Character read: " + c);

        int  j = lnis.getLineNumber();
        System.out.println(" at line: " + j);
      }
    }

  }
}