Hi,
I'm trying to store values from a text file into my array list
My text file has two lines
Output incorrectly shows:
test2 test2_value
test2 test2_value
Which I want to show:
test1 test1_value
test2 test2_value
I'm trying to store values from a text file into my array list
Code:
public static ArrayList getAccts(String file)
{
//Attributes
String aRecord;
StringTokenizer strings;
Account anAcct = new Account(); //Intialize obj
ArrayList<Account> anAL= new ArrayList<Account>();
try
{
FileReader inStream = new FileReader("myFile.txt");
BufferedReader ins = new BufferedReader(inStream);
while ((aRecord=ins.readLine())!= null)
{
strings = new StringTokenizer(aRecord,"?"); //toekenizer
if (strings.countTokens() == 2) {
a = strings.nextToken();
b = strings.nextToken();
}
anAcct = new Account (a,b);
anAL.add(anAcct);
}
ins.close();
}
catch(IOException e)
{
e.printStackTrace();
}
return anAL;
}
Code:
test1?test1_value? test2?test2_value?
test2 test2_value
test2 test2_value
Which I want to show:
test1 test1_value
test2 test2_value
Comment