- Apache Commons IO 教程
- Apache Commons IO - 首頁
- Apache Commons IO - 概覽
- Apache Commons IO - 環境設定
- Apache Commons IO - IOUtils
- Apache Commons IO - FileUtils
- Apache Commons IO - FilenameUtils
- Apache Commons IO - FileSystemUtils
- Apache Commons IO - IOCase
- Apache Commons IO - LineIterator
- Apache Commons IO - NameFileFilter
- Apache Commons IO - WildcardFileFilter
- Apache Commons IO - SuffixFileFilter
- Apache Commons IO - PrefixFileFilter
- Apache Commons IO - OrFileFilter
- Apache Commons IO - AndFileFilter
- Apache Commons IO - FileEntry
- Apache Commons IO - FileAlterationObserver
- Apache Commons IO - FileAlterationMonitor
- Apache Commons IO - NameFileComparator
- Apache Commons IO - SizeFileComparator
- LastModifiedFileComparator
- Apache Commons IO - TeeInputStream
- Apache Commons IO - TeeOutputStream
- Apache Commons IO - 有用資源
- Apache Commons IO - 快速指南
- Apache Commons IO - 有用資源
- Apache Commons IO - 討論
Apache Commons IO - LineIterator
LineIterator 提供了一種靈活的方式來處理基於行的檔案。
類宣告
以下是 org.apache.commons.io.LineIterator 類的宣告 -
public class LineIterator extends Object implements Iterator<String>, Closeable
LineIterator 類的示例
以下是我們需要進行解析的輸入檔案 -
Welcome to TutorialsPoint. Simply Easy Learning. Learn web technologies, prepare exams, code online, all at one place.
IOTester.java
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.LineIterator;
public class IOTester {
public static void main(String[] args) {
try {
usingLineIterator();
} catch(IOException e) {
System.out.println(e.getMessage());
}
}
public static void usingLineIterator() throws IOException {
//get the file object
File file = FileUtils.getFile("input.txt");
try(LineIterator lineIterator = FileUtils.lineIterator(file)) {
System.out.println("Contents of input.txt");
while(lineIterator.hasNext()) {
System.out.println(lineIterator.next());
}
}
}
}
輸出
它將列印以下結果 -
Contents of input.txt Welcome to TutorialsPoint. Simply Easy Learning. Learn web technologies, prepare exams, code online, all at one place.
廣告