package io;
import java.io.FileReader;
import java.io.LineNumberReader;
public class LineNumberReaderTest {
public static void main(String[] args) throws Exception{
int lineNumber = getFileLineNumber("D:/Projects/JDK/src/io/info.txt");
System.out.println("the line number of specified file is "+lineNumber);
}
public static int getFileLineNumber(String filePath) throws Exception{
LineNumberReader lineNumberReader = new LineNumberReader(new FileReader(filePath));
// it will return the number of characters actually skipped
lineNumberReader.skip(Long.MAX_VALUE);
int lineNumber = lineNumberReader.getLineNumber();
lineNumber++;
lineNumberReader.close();
return lineNumber;
}
}