|
Java™ by example!
|
|
|
How do keep track of line numbers when reading a file with a Reader?
Use the class filtered reader LineNumberReader. While getting the actual read buffer from the reader, you can also retrieve the current line number. You can also (re)set it with setLineNumber. This does not affect the file pointer.
This example reads in a textfile and displays a separator line every 10 lines. Main.java:
Further Information
Author of answer: Joris Van den Bogaert
Comments to this answer are only viewable by members. Login or become a member!
|
|
|
|
|