If I use this code, and the textfile with the right text:
package me.ruban.AccountManager;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;`
public class Login {
private String readNickname;
private String readPassword;
private String inputNickname;
private String inputPassword;
private static String[] accountDetails;
private static String line;
private boolean exists = true;
private boolean login = false;
public Login(String inputNickname, String inputPassword) throws IOException {
this.inputNickname = inputNickname;
this.inputPassword = inputPassword;
if(new File(inputNickname + ".acc").exists() == false) {
System.out.println("[Login] This account does not exists!");
exists = false;
}
if(!exists == false) {
try {
Scanner input = new Scanner(new File(inputNickname + ".acc"));
line = "";
while (input.hasNextLine()) {
System.out.println("[Login] Reading...");
line += input.nextLine() + " ";
}
input.close();
System.out.println("[Login] Loaded " + inputNickname + ".acc succesfully.");
} catch (Exception e) {
e.printStackTrace();
}
accountDetails = line.split(" ");
if(accountDetails[0] == inputNickname) {
if(accountDetails[1] == inputPassword) {
login = true;
System.out.println("[Login] Login is aviable!");
}
}
}
}
public boolean getLogin() {
return login;
}
public boolean getExists() {
return exists;
}
public String getLine() {
return line;
}
public static void main(String[]args) throws IOException {
Login l = new Login("username", "password");
System.out.println();
System.out.println(accountDetails[0]);
System.out.println(accountDetails[1]);
System.out.println();
System.out.println(l.getLogin());
}
}
My output will be:
[Login] Reading...
[Login] Reading...
[Login] Loaded username.acc succesfully.
username
password
false
This is not what I wan't, because the false should be true according to my code and my textfile. So my question is: how to get the false to true.
Thanks