-3
The teacher passed an activity, which is for you to put the files in a txt, read, change and delete... I am programming the search function, and it is not working. You could help me?
public void searchUser(String login){
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
if(divider[1].equals(login)){
System.out.println(divider[1]);
break;
}
}
br.close();
fr.close();
} catch (Exception ex) {
System.out.println("Erro");
}
}
That’s the code part. It should read line by line from login.txt, through the split separate the line into parameters of a vector, and compare the input with one of these parameters that is already defined. It seems to me that he is not passing the other lines and is only reading the first, when I "seek" the one of the first line, he returns perfectly, the one of the others not... why?
It seems to me that he is not reading the next lines. Because then, he will read a.txt file right? He’s supposed to go line by line, but it seems to me he stops at the first one and doesn’t go any further. When I put it in main, if it’s from the first line, it returns, if it’s not, it returns nothing, it’s as if it doesn’t jump to the next line. Sorry, it’s the first comment I make here haha and thank you.
– V. Cacau