I'm trying to write a method, which checks if a given string exists in a .txt file, but it seems like my if/else statement isn't working correctly.
public void ChcekIfPasswordExsists(String check) throws FileNotFoundException{
BufferedReader reader = new BufferedReader(new FileReader("Passwords.txt"));
Scanner fileScanner = new Scanner(reader);
while(fileScanner.hasNextLine()){
final String line = fileScanner.next();
if(line.contains(check)){
System.out.println("Password for " + check + " already exsits");
break;
}
else{
System.out.println(check + " is usable");
break;
}
}
}
This is where I'm calling the method:
System.out.println("Enter the name of the app or website,\nwhere password is going to be use:");
useCase = s.nextLine();
ChcekIfPasswordExsists(useCase);
I have looked at countless other posts with no effect. No matter what, it seems like the code skips the "if" statement and directly jumps to the "else" statement.