Searching a .dat file
Hi Guys,
I'm a newbie at Java programming, Please can you help me with the following question!
I have a Phone.dat file, containing the names and numbers of people
Example
rohan076
384738292
mark
3829482738
kristin
4938209384
Now I want to write a program which ask the user to input a name, the program has to search through this Phone.dat file and return the phone number if there is a match, otherwise give a 'no record exist' message.
please help.
Thank you,
rohan076
[569 byte] By [
rohan076] at [2007-11-11 8:16:06]

# 1 Re: Searching a .dat file
Take a look at the Scanner class. It will allow you to process a file directly (there is a constructor which uses a file name as a parameter). The scanner object is an array of tokens created from the stream allow you to step through the tokens created by the new line character ... scan through the content, using the hasNext( stringToCheck ) method ... if returns true, then use the next() method to return the content following the recognized string - it should be your number.
nspils at 2007-11-11 22:35:53 >

# 2 Re: Searching a .dat file
the following link displays file manipulate free downloads, there is a downlod called search text file, which is similar to what you want. have a look at it. let me know if thats what ur after.
http://www.java.codeyourself.com/Category.php?Category=File-Manipulation
major at 2007-11-11 22:36:58 >

# 3 Re: Searching a .dat file
Thanks a lot MAJOR. Will work with that example and change it to suit my requirements.
Thanks to nspils too, will work in that direction also
# 5 Re: Searching a .dat file
thanks arul, i was using a text file and i successfully implemented the Scanner class the search for records.