Get the number of lines and characters in a file using Java

This example demonstrates one of the ways to find the number of lines and characters in a file using Java Programming Language

Here is the block of code that will make the task easy for you

 
The file named “file.txt” here in this example is located inside the folder named codedbug on drive E. Change the address in the above program to point the file you want to find the number of lines and characters of.
Here is the visual view of the file “file.txt” and sample contents.
Input File
When we will run this program for the above file and with sample contents in the image. It will produce an output as:
Output
Total number of lines : 3 Length of file: 94

Leave a Reply

Contact Us
close slider
Contact Us

How can we help you with?