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, next
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
iterator
forEach, spliterator
forEachRemaining, hasNext, next, remove
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抛出此异常protected String computeNext()
ComputeIter
computeNext
in class ComputeIter<String>
public void close()
close
in interface Closeable
close
in interface AutoCloseable
protected boolean isValidLine(String line)
line
- 需要验证的行Copyright © 2024. All rights reserved.