In this Post we are going to write code to get the total number of lines count from each files in a directory. Here I am going to use java.nio, java.io and java.util.stream packages.
In this example I am counting the number of lines from files with fileExtension as ".java" from the below Directory, But one can use the same program to count the number of lines of multiple ".json",".yaml", ".xml", ".text", ".vm" any other extensions of files under a directory.
So Here is the Code snippet through which get us the total number of lines from each file under a Directory.
File MomoController.java has 113 number of lines
File MomoWithdrawalController.java has 34 number of lines
File SMSController.java has 63 number of lines
Process finished with exit code 0
So in this simple java code example we have learned how o get the total number of lines count from multiple files in a directory.
GitHub Link : rajivksingh13/teachlea
Please feel free to provide your valuable comments, Thanks.
Please feel free to provide your valuable comments, Thanks.
Ref:
https://mkyong.com/java/how-to-get-the-total-number-of-lines-of-a-file-in-java/
0 Comments