3
This code should take all the elements of a login.txt file and put inside a user array.
public ArrayList<User> takeAll(){
ArrayList<User> list = new ArrayList();
User u = new User();
String result = "";
try {
FileReader fr = new FileReader("C:\\Users\\vanes\\Documents\\WEBprog\\Archive\\login.txt");
BufferedReader br = new BufferedReader(fr);
while (br.ready()) {
result = br.readLine() + "\n";
String divider[] = new String[2];//split
divider = result.split(";"); //split
u.setName(divider[0]);
u.setLogin(divider[1]);
u.setPassword(divider[2]);
// System.out.println(u.getName()+";"+u.getLogin()+";"+u.getPassword());
list.add(u);
}
br.close();
fr.close();
} catch (Exception ex) {
System.out.println("Erro");
}
for (int i = 0; i < list.size(); i++)
System.out.println(list.get(i).getLogin());
return list;
}
I see it being added the way it is to be. However, when I try to print before the "Return list", the result appears the same for all nodes. I wonder where the error is.
It seems to me that he is not recording properly inside the while. I’ve tested the piece of code somewhere else and it works perfectly, that part of the for really, the error appears to be inside the while, but I can’t see.
Where is the print?
– user28595