Each row contains a persons info. The best thing to do is create a class that holds each row. Here is an example:
class PersonInfo
{
private String name;
private int age;
private String address;
public PersonInfo(String name, int age, String address)
{
this.name=name;
this.age=age;
this.address=address;
}
}
Then in your loop above you should write:
//create array outside
PersonInfo[] listOfInfo = new PersonInfo[100]; //change 100 to the desired size!
//maintain # of items in array
int listOfInfoSize=0;
//read lines
while (line != null)
{
StringTokenizer tokens = new StringTokenizer(line, ", \t");
//get three tokens
String nameToken = tokens.nextToken();
String ageToken = tokens.nextToken();
String addressToken = tokens.nextToken();
//create personinfo object
PersonInfo obj = new PersonInfo(nameToken, ageToken, addressToken);
//add to array
listOfInfo[listOfInfoSize++]=obj;
}
As you see above, the array will hold all the PersonInfo objects. Each PersonInfo object represents a row in the text file. You should add getter methods to the PersonInfo class. Then you can use this array to get any info you need.
For more help, www.NeedProgrammingHelp.com
NPH
Junior Poster in Training
55 posts since May 2005
Reputation Points: 10
Solved Threads: 1