-3
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;
}
嘗試從行中刪除「密碼:」。 (密碼) 它將得到「密碼:」+文本後的密碼(密碼) 我想刪除「密碼:」,所以我剩下的只是純文本。字符串替換不工作,因爲我認爲它應該
'字符串'是不可變的。 –
'password = password.replace(「Password:」,「」);'這個人有很多重複。 – dasblinkenlight
@dasblinkenlight包含大量短語「字符串替換不工作」。 – chrylis