public static boolean passwordConfirmed() {
String attempt = JOptionPane.showInputDialog("Password: ");
FileReader fstream = null;
String password = "";
try {
fstream = new FileReader("pass.txt");
BufferedReader in = new BufferedReader(fstream);
password = in.readLine();
password.replace("Password: ", " ");
System.out.println(password);
} catch (IOException e) {
e.printStackTrace();
}
if (attempt.equals(password)) {
System.out.print("True");
return true;
} else System.out.println("false");
return false;
}
Trying to remove "Password: " from the line. It gets the line "Password: " + text afterwards (Password) I want to remove the "Password: ", so all i have left is purely the text afterwards.
Always re-assign it.
Strings are immutable in Java, meaning you can't modify an existing instance of it. By re-assigning it, you'll be capturing the new value of the string into an existing variable.