public class LineIter extends ComputeIter<String> implements IterableIter<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
|
protected String |
computeNext()
|
protected boolean |
isValidLine(String line)
重写此方法来判断是否每一行都被返回,默认全部为true
|
finish, hasNext, nextclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waititeratorforEach, spliteratorforEachRemaining, hasNext, next, removepublic LineIter(InputStream in, Charset charset) throws IllegalArgumentException
in - InputStreamcharset - 编码IllegalArgumentException - reader为null抛出此异常public LineIter(Reader reader) throws IllegalArgumentException
reader - Reader对象,不能为nullIllegalArgumentException - reader为null抛出此异常protected String computeNext()
ComputeItercomputeNext in class ComputeIter<String>public void close()
close in interface Closeableclose in interface AutoCloseableprotected boolean isValidLine(String line)
line - 需要验证的行Copyright © 2025. All rights reserved.