Is there an easy way of counting line numbers? Or do you have to go through the entire file?

Shahram Khorsand

You have to go through the entire file.

try {
  LineNumberReader lnr = new LineNumberReader(new FileReader(filename));
  String s;
  while ((s = lnr.readLine()) != null);
  System.out.println("Lines: " + lnr.getLineNumber());
0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.