Java LineNumberReader .getLineNumber ()

Syntax

LineNumberReader.getLineNumber() has the following syntax.

public int getLineNumber()

Example

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


//from ww w.j a va2s .c  o  m

import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;

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

    FileReader fr = new FileReader("C:/test.txt");
    LineNumberReader lnr = new LineNumberReader(fr);

    // sets the current line number
    lnr.setLineNumber(100);

    // get the current line number
    int i = lnr.getLineNumber();

    // print the current line number
    System.out.print("Current line number: " + i);
        lnr.close();
  }

}