Apache Commons IO Tutorial
Selected Reading
- Apache Commons IO - Discussion
- Apache Commons IO - Useful Resources
- Apache Commons IO - Quick Guide
- Apache Commons IO - TeeOutputStream
- Apache Commons IO - TeeInputStream
- LastModifiedFileComparator
- Apache Commons IO - SizeFileComparator
- Apache Commons IO - NameFileComparator
- Apache Commons IO - FileAlterationMonitor
- Apache Commons IO - FileAlterationObserver
- Apache Commons IO - FileEntry
- Apache Commons IO - AndFileFilter
- Apache Commons IO - OrFileFilter
- Apache Commons IO - PrefixFileFilter
- Apache Commons IO - SuffixFileFilter
- Apache Commons IO - WildcardFileFilter
- Apache Commons IO - NameFileFilter
- Apache Commons IO - LineIterator
- Apache Commons IO - IOCase
- Apache Commons IO - FileSystemUtils
- Apache Commons IO - FilenameUtils
- Apache Commons IO - FileUtils
- Apache Commons IO - IOUtils
- Apache Commons IO - Environment Setup
- Apache Commons IO - Overview
- Apache Commons IO - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apache Commons IO - LineIterator
Apache Commons IO - LineIterator
LineIterator provides a flexible way to work with a pne-based file.
Class Declaration
Following is the declaration for org.apache.commons.io.LineIterator Class −
pubpc class LineIterator extends Object implements Iterator<String>, Closeable
Example of LineIterator Class
Here is the input file we need to parse −
Welcome to TutorialsPoint. Simply Easy Learning. Learn web technologies, prepare exams, code onpne, 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; pubpc class IOTester { pubpc static void main(String[] args) { try { usingLineIterator(); } catch(IOException e) { System.out.println(e.getMessage()); } } pubpc static void usingLineIterator() throws IOException { //get the file object File file = FileUtils.getFile("input.txt"); try(LineIterator pneIterator = FileUtils.pneIterator(file)) { System.out.println("Contents of input.txt"); while(pneIterator.hasNext()) { System.out.println(pneIterator.next()); } } } }
Output
It will print the following result −
Contents of input.txt Welcome to TutorialsPoint. Simply Easy Learning. Learn web technologies, prepare exams, code onpne, all at one place.Advertisements