It's not a secret anymore!
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 Storm Applied this week in the Other Open Source APIs 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: 541
    
    2

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.







Sent from my IBM 360 mainframe
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Looping through a text file with an iterator