The Java language provides a lot og useful classes to handle files, the LineNumberReader class is one of them.
In the following method I'm using the LineNumberReader to retrieve the length of a text file in terms on number of lines.
private int getNumberOfLines(String filename) { int lines = 0; LineNumberReader lnr; try { lnr = new LineNumberReader(new FileReader(new File(filename))); lnr.skip(Long.MAX_VALUE); lines = lnr.getLineNumber(); lnr.close(); } catch (FileNotFoundException ex) { Logger.getLogger(FbFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FbFrame.class.getName()).log(Level.SEVERE, null, ex); } return (lines); }
To use this method you have to pass to it the path to the text file you want to analyze, and you'll get the number of lines contained in it.
Gg1