Basically doing a project for school work and it needs to have a login system and it can be as basic as i like so i am just storing the usernames/passwords in a text file. i have written code to read the file line by line and store each line in a variable, this all works but when i am testing to see if i can compare it to string even though they are the same it does not seem to think so, i have ran other tests to make sure my if/else statements are correct and have ran into no other issues, my current theory is that it has something to do with the fact that the usernames and passwords are stored with "\n" after to make them appear on different lines of the text file.
public static void main(String[] args) throws IOException {
File file = new File("C:/Users/Will/Desktop/UnPs.txt");
Scanner scan = new Scanner(file);
while(scan.hasNextLine()) {
String passCheck = scan.nextLine();
if(passCheck == "test2,Test2") {
System.out.println("Test1");
}
else if(passCheck != "test2,Test2") {
System.out.println(passCheck);
System.out.println("not found");
}
}
}
the output of running the code is:
test1,Test1 not found test2,Test2 not found test3,Test3 not found
but in my head after it reaches the second line of the file it should have the value of passCheck as "test2,Test2". if you want to see how the usernames and passwords are written to the file just ask but as i said my theory is that the "\n" is related