aspose file tools*
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
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