public class LineIter extends Object implements Iterator<String>, Iterable<String>, Closeable, Serializable
LineIterator it = null; try { it = new LineIterator(reader); while (it.hasNext()) { String line = it.nextLine(); // do something with line } } finally { it.close(); }此类来自于Apache Commons io
Constructor and Description |
---|
LineIter(InputStream in,
Charset charset)
构造
|
LineIter(Reader reader)
构造
|
Modifier and Type | Method and Description |
---|---|
void |
close()
关闭Reader
|
boolean |
hasNext()
|
protected boolean |
isValidLine(String line)
重写此方法来判断是否每一行都被返回,默认全部为true
|
Iterator<String> |
iterator() |
String |
next()
返回下一行内容
|
String |
nextLine()
返回下一行
|
void |
remove()
不支持移除
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
forEach, spliterator
public LineIter(InputStream in, Charset charset) throws IllegalArgumentException
in
- InputStream
charset
- 编码IllegalArgumentException
- reader为null抛出此异常public LineIter(Reader reader) throws IllegalArgumentException
reader
- Reader
对象,不能为nullIllegalArgumentException
- reader为null抛出此异常public boolean hasNext() throws IORuntimeException
hasNext
in interface Iterator<String>
true
表示有更多行IORuntimeException
- IO异常public String next() throws NoSuchElementException
next
in interface Iterator<String>
NoSuchElementException
- 没有新行public String nextLine() throws NoSuchElementException
NoSuchElementException
- 没有更多行public void close()
close
in interface Closeable
close
in interface AutoCloseable
public void remove()
remove
in interface Iterator<String>
UnsupportedOperationException
- 始终抛出此异常protected boolean isValidLine(String line)
line
- 需要验证的行Copyright © 2021. All rights reserved.