Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Count the number of lines in each file in a directory

843789Sep 22 2009 — edited Sep 22 2009
Hello,

I would like to count the number of lines for each file in my directory and subdirectories.
I wonder how can I count the lines of the specified files?

Here is the program which is listed the files in the specified directory:
                    String path = "C:/User/Studies/Pracices/src/Pract1";
	  String files;
	  File folder = new File(path);
	  File[] listOfFiles = folder.listFiles(); 
	 
	  for (int i = 0; i < listOfFiles.length; i++) 
	  {
	 
	   if (listOfFiles.isFile()) 
{
files = listOfFiles[i].getName();

System.out.println(files);
}
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 20 2009
Added on Sep 22 2009
8 comments
494 views