I created a class that verifies usernames & passwords in a text file
When debugging my code I noticed that when i used system.out.print in line 20 the item that was outputted was only the last one on my text file. I know that using println would fix it but i was wondering what what causing this? just to expand my knowledge.
i assumed this is what should have printed out
jon:123432luis:358273frogboy156:32423false
but i get this instead
frogboy15632423false
class
mport java.io.File;
import java.util.Scanner;
public class verificaiton {
public static void verifyLogin(String username, String password) {
boolean found = false;
String tempUsername = "";
String tempPassword = "";
try {
Scanner x = new Scanner(new File("src/info.txt"));
x.useDelimiter("[:\n]");
while (x.hasNext() && !found) {
tempUsername = x.next();
tempPassword = x.next();
System.out.print(tempUsername + tempPassword + "");
if (tempUsername.trim().equals(username) && tempPassword.trim().equals(password.trim())) {
found = true;
}
}
x.close();
System.out.println(found);
}
catch(Exception e){
System.out.println("Error");
}
}
}
main
public class main {
public static void main(String[] args){
verificaiton check = new verificaiton();
check.verifyLogin("Luis", "32534");
}}
text file
jon:123432
luis:358273
frogboy156:32423