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| 构造器和说明 |
|---|
LineIter(InputStream in,
Charset charset)
构造
|
LineIter(Reader reader)
构造
|
public LineIter(InputStream in, Charset charset) throws IllegalArgumentException
in - InputStreamcharset - 编码IllegalArgumentException - reader为null抛出此异常public LineIter(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 - 始终抛出此异常protected boolean isValidLine(String line)
line - 需要验证的行Copyright © 2019. All rights reserved.