我想检查文件名和密码文件是否正确继续代码..否则检查密码文件会出错。
我的代码是:
Scanner scanInputUser = new Scanner(System.in);
System.out.println("Please Enter UserName:");
String fileName = scanInputUser.nextLine();
fileHandler.setUserName(fileName); // This file name has already been defined in another class.
//and using this method with instance class..
try {
System.out.println("Please Enter Password:");
String passSaver = scanInputUser.nextLine();
cryptography.setKeyUser(passSaver); // password decrypt save to same file.
//This method has already been defined in another class.
fileHandler.passwordSaver(passSaver);
} catch (Exception e) {
e.printStackTrace();
}
//TODO check correct password for file name
(note: password file name saved to the same file).
答案 0 :(得分:-1)
您可能正在寻找equals(Object o)
(Oracle Doc),但我无法确定您对此问题的描述。
简短的例子:
if (passSaver.equals(passPhrase)) {
dostuff();
}