I am reading from a file and while i know how to work with those i am trying to read the line. get all the fields. then store them in a class with those fields. then store that object in a vector.
Heres how i deal with reading the stuff from the file:
StringTokenizer tokens;
String field1,field3;
int field2;
BufferedReader myFile = new BufferedReader(new Filereader("textfile.txt"));
String str1 = myFile.readLine();
while (str1 != null){
tokens = new StringTokenizer(str1);
while(tokens.hasMoreTokens()){
field1 = tokens.nextToken();
field2 = Integer.parseInt(tokens.nextToken());
field3 = tokens.nextToken();}
str1 = myFile.readLine();
// THIS is where i need code to set values on the Class Fields
//read below for more explanation
}
Now thats just sample code i just typed to show that im not trying to get help without posting some code.
Next i have a class
class Fields{
String name,lastname;
int age;
public void setage(int myAge){
age = myAge;
}
public int getage(){return age;}
//i have more methods to get to get and set the fields in this class.
// i also have a 3 arg constructor and a no arg constructor.
}
Now here is my question. How can i make it so after i read all those fields. set them to a new fields object then place all of them in a vector. There is going to be more than one line in the text file.
class doStuff{
Vector<Fields> fieldVec = new Vector<Fields>();
}
Now i want to read from the file in the main method.which i posted sample code up up above. Then initialize a Fields object with those fields. then store it in a vector.