Meaningless Drivel is fun!
The moose likes I/O and Streams and the fly likes Read Line From file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Read Line From file" Watch "Read Line From file" New topic

Read Line From file

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

I've used text files to store data about students
each line consists of student name, SSN, and score
This is the problem:Given SSN, search into the file and if you find matching read the current line from beginning to display such output
John F Smith:50.5
I've developed this class
but when the matching occur i cannot read the the current line from beginning
Can you help me in this???

I Hear I Forget, I See I Remember, I Do I Understand.
Greg Charles

Joined: Oct 01, 2001
Posts: 2963

I would read the file line by line rather than use a Scanner. Look for the match in each line, and if you find one, you already have the line in a String variable. Also, you don't waste time trying to match an SSN with the other tokens, which may be names or scores.
It is sorta covered in the JavaRanch Style Guide.
subject: Read Line From file
It's not a secret anymore!