Monday, 25 April 2016

How to get the total number of lines of a file ?


To get total number of lines of a file, use 
LineNumberReader

Example
FileReader fr = new FileReader(new File("xyz"));
LineNumberReader lnr = new LineNumberReader(fr);
int n = 0;
while (lnr.readLine() != null){
    n++;
}
System.out.println("Total number of lines : " + n);
lnr.close();

No comments:

Post a Comment

Note: only a member of this blog may post a comment.