wood burning stoves 2.0*
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
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Read Line From file" Watch "Read Line From file" New topic
Author

Read Line From file

Roger Fed
Ranch Hand

Joined: Oct 17, 2010
Posts: 82

Hello
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???
thanks.


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

Joined: Oct 01, 2001
Posts: 2835
    
  11

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
 
Similar Threads
Inheritance
Need help with output of a program
Reading file Input and Output
Confused with file read
Creating array of objects from user input and saving to a file