public class LineIterator extends Object implements Iterator<String>, Closeable
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| 构造器和说明 |
|---|
LineIterator(InputStream in,
Charset charset)
构造
|
LineIterator(Reader reader)
构造
|
public LineIterator(InputStream in, Charset charset) throws IllegalArgumentException
in - InputStreamcharset - 编码IllegalArgumentException - reader为null抛出此异常public LineIterator(Reader reader) throws IllegalArgumentException
reader - Reader对象,不能为nullIllegalArgumentException - reader为null抛出此异常public boolean hasNext()
throws IORuntimeException
hasNext 在接口中 Iterator<String>true 表示有更多行IORuntimeException - IO异常public String next() throws NoSuchElementException
next 在接口中 Iterator<String>NoSuchElementException - 没有新行public String nextLine() throws NoSuchElementException
NoSuchElementException - 没有更多行public void close()
close 在接口中 Closeableclose 在接口中 AutoCloseablepublic void remove()
remove 在接口中 Iterator<String>UnsupportedOperationException - alwaysprotected boolean isValidLine(String line)
line - the line that is to be validatedCopyright © 2018. All rights reserved.