Class LineIterator

java.lang.Object
org.apache.commons.io.LineIterator
All Implemented Interfaces:
Closeable, AutoCloseable, Iterator<String>

public class LineIterator extends Object implements Iterator<String>, Closeable
An Iterator over the lines in a Reader.

LineIterator holds a reference to an open Reader. When you have finished with the iterator you should close the reader to free internal resources. This can be done by closing the reader directly, or by calling the close() or closeQuietly(LineIterator) method on the iterator.

The recommended usage pattern is:

 LineIterator it = FileUtils.lineIterator(file, StandardCharsets.UTF_8.name());
 try {
   while (it.hasNext()) {
     String line = it.nextLine();
     // do something with line
   }
 } finally {
   it.close();
 }
 
Since:
1.2