wood burning stoves*
The moose likes I/O and Streams and the fly likes Looping through a text file with an iterator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Looping through a text file with an iterator" Watch "Looping through a text file with an iterator" New topic
Author

Looping through a text file with an iterator

Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 174

Just thought somebody might find this interesting/useful.
I wanted to use the new 'for' syntax to loop through all the lines in a text file; something I find myself doing quite often.

A simple example:


It required making two classes: FileLineIterable, and FileLineIterator.
You might find this useful as an example for implementing your own iterator class.





 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looping through a text file with an iterator
 
Similar Threads
save properties file without affecting existing comments.
Need to read and write data from file.
Java: Convert a binary file to "text" and back again.
Syntax error in INSERT INTO statement
Using Swing to display an array from text file issues