Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Send lines of a file to something such as an arrayList

 
M Strasser
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
jason adam
Chicken Farmer ()
Ranch Hand
Posts: 1932
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic