내가 만든 두 가지 기능이 있습니다. 1은 암호를 변경하고 1은 파일을 삭제하는 것입니다. 그래서 내 의도는 먼저 암호 변경 기능을 실행 한 다음 파일 삭제를 수행하는 것입니다. 코드가 제대로 실행되고 새 파일에 새 암호가 생성됩니다. 그러나 파일을 삭제하려고 할 때 작동하지 않고 이름을 바꾸려면 도움이 필요합니다 pls
public static void replaceAdminPassword()throws IOException{
try {
Scanner read = new Scanner(System.in);
System.out.println("Enter Old Password: ");
String oldPass = read.nextLine();
String UserPHash = Utility.getHash(oldPass);
System.out.println("Enter New Password: ");
String newPass = read.nextLine();
String UserNHash = Utility.getHash(newPass);
read = new Scanner(new File("admin.dat"));
String line;
String[] details;
String input = "";
File fout = new File("out.dat");
FileOutputStream fos = new FileOutputStream(fout);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
while (read.hasNextLine()){
line = read.nextLine();
details = line.split("\\|");
if(details[0].equalsIgnoreCase(UserPHash)){
input = UserNHash;
bw.write(input);
System.out.println("Password Changed.");
}
}
bw.close();
replaceAdminFile();
}catch (FileNotFoundException ex){
System.out.println("file not found");
}
}
public static void replaceAdminFile(){
File oldFile = new File("admin.dat");
File newFile = new File("out.dat");
oldFile.delete();
newFile.renameTo(oldFile);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다