Hi, my codes if statement returns false for some reason. I tried different variation yesterday and today morning and nothing works. Could someone look my code. I got File file users.txt where the usernames are stored.
public static void checkUser(String userName, char[] passWord) {
FileInputStream fIn;
DataInputStream dInput = null;
try {
fIn = new FileInputStream(file);
dInput = new DataInputStream(fIn);
BufferedReader lukija = new BufferedReader(new InputStreamReader(dInput));
String userName2 = "";
while (userName2 != null) {
userName2 = lukija.readLine();
System.out.println(userName2);
System.out.println(userName);
if (userName.equals(userName2)) {
System.out.println("sisään");
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (dInput != null) {
try {
dInput.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Actually username2 is stored in the users.txt and username comes from user input just a normal JTextField.