aspose file tools*
The moose likes I/O and Streams and the fly likes Send lines of a file to something such as an arrayList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Send lines of a file to something such as an arrayList" Watch "Send lines of a file to something such as an arrayList" New topic
Author

Send lines of a file to something such as an arrayList

M Strasser
Greenhorn

Joined: Mar 30, 2004
Posts: 1
I have a text file that I want to go through and put specific entries in to an arrayList (or any other list). I want to select a line by matching up a piece of string. For example, I want to take all lines that have "B204" somewhere in them and put them into an arrayList. I already know how to read the file:
BufferedReader textline = new BufferedReader(new FileReader("textfile.txt"));
what do I do next?
Thanks
Micah
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Create a new ArrayList.
loop reading lines.
check the lines for your pattern (Pattern, Matcher, String.matches(...) in javadocs).
Add matching lines to the list.
handle exceptions.
close file.
done.


http://home.arcor.de/hirnstrom/bewerbung
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Micah, welcome to the Ranch!
We don't have a lot of rules, but we do have our Naming Policy. Specifically, last names should not be initials. First and middle names are fine, but last names should be "realistic" looking. Doesn't have to be your real last name (though we prefer that), but something more than just a letter.
Head over to your profile and change your display name please to conform to our policy.
Thanks!
 
jQuery in Action, 2nd edition
 
subject: Send lines of a file to something such as an arrayList