? LineIterator
java.lang.Object
org.apache.commons.io.LineIterator
- ????????:
Closeable
,AutoCloseable
,Iterator<String>
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, "UTF-8"); try { while (it.hasNext()) { String line = it.nextLine(); // do something with line } } finally { it.close(); }
- ???????:
- 1.2
-
?????
??? -
????
??????????void
close()
Closes the underlyingReader
.static void
closeQuietly
(LineIterator iterator) ????As of 2.6 deprecated without replacement.boolean
hasNext()
Indicates whether theReader
has more lines.protected boolean
isValidLine
(String line) Overridable method to validate each line that is returned.next()
Returns the next line in the wrappedReader
.nextLine()
Returns the next line in the wrappedReader
.void
remove()
Unsupported.??????? java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
???????? java.util.Iterator
forEachRemaining
-
???????
-
LineIterator
Constructs an iterator of the lines for aReader
.- ??:
reader
- theReader
to read from, not null- ??:
IllegalArgumentException
- if the reader is null
-
-
??????
-
hasNext
Indicates whether theReader
has more lines. If there is anIOException
thenclose()
will be called on this instance.- ???:
hasNext
????Iterator<String>
- ??:
true
if the Reader has more lines- ??:
IllegalStateException
- if an IO exception occurs
-
isValidLine
Overridable method to validate each line that is returned. This implementation always returns true.- ??:
line
- the line that is to be validated- ??:
- true if valid, false to remove from the iterator
-
next
Returns the next line in the wrappedReader
.- ???:
next
????Iterator<String>
- ??:
- the next line from the input
- ??:
NoSuchElementException
- if there is no line to return
-
nextLine
Returns the next line in the wrappedReader
.- ??:
- the next line from the input
- ??:
NoSuchElementException
- if there is no line to return
-
close
Closes the underlyingReader
. This method is useful if you only want to process the first few lines of a larger file. If you do not close the iterator then theReader
remains open. This method can safely be called multiple times.- ???:
close
????AutoCloseable
- ???:
close
????Closeable
- ??:
IOException
- if closing the underlyingReader
fails.
-
remove
Unsupported.- ???:
remove
????Iterator<String>
- ??:
UnsupportedOperationException
- always
-
closeQuietly
????As of 2.6 deprecated without replacement. Please use the try-with-resources statement or handle suppressed exceptions manually.Closes aLineIterator
quietly.- ??:
iterator
- The iterator to close, ornull
.- ????:
-