Using the LineNumberReader class

LineNumberReader is a subclass of the BufferedReader class and allows you to keep track of which line you’re currently processing.
It also enables you to alter the current line number if you wish to start from another number.
This example constructs a LineNumberReader object for a file and reads each line until the end of file is reached.
Each line is printed out along with the line number.

This is what the input file (myFile.txt) looks like:

And the code:

And this is what the output will be when we run the code:

Search for more Java info on this site here:
Custom Search

Please type any questions here.