Click to See Complete Forum and Search --> : to select certain details from text file


project123
11-28-2006, 03:53 AM
hi,
i was wondering how can i select n display only certain items from the text file. lets say i have name , address, birthdate, location in the file.
However, i would only like to retrieve the address. how can i do that? thanks

currently i have managed to select out all the info by using this following codes.


File inputFile = new File("C:\\temp\\test.txt");
try{
FileReader in= new FileReader(inputFile);
int c;
String str;

while ((c = in.read()) != -1) {
System.out.print((char) c);

}
in.close();

}catch (FileNotFoundException e){
System.out.println("File Does not exist");
System.exit(1);

anubis
11-28-2006, 09:14 AM
what does the data in the file look like?
is it something like:
"Name: John
Address: 123 something st.
Birthdate: 12/3/78"

or is it something else?

project123
11-28-2006, 08:08 PM
it looks like this.

name age location

john 13 usa
peter 14 au
jane 15 seoul

lets say i would only like to select out the age.how do i do tht?
thanks

nspils
11-28-2006, 09:02 PM
The Scanner class is designed to perform the very task you are looking at.

project123
11-29-2006, 01:06 AM
where can i find it?
thanks

nspils
11-29-2006, 01:11 AM
Take a look at the API documentation

http://java.sun.com/j2se/1.5.0/docs/api/