越來越ovewritten我使用BufferWriter格式以及嘗試的FileWriter和PrintWriter的每一個true語句,但他們都表現得一樣的,如果我只是用一個簡單的新文件。每次我運行程序結束時,都會調用寫入保存的數據的函數。最終發生的是它覆蓋最後保存的數據。我也有其他代碼塊來處理該文本文件,並重新格式化它們也沒有做任何事情。輸出flles一直在Java中
//saves user information to "Users.txt" which will be called in the finally block after choice switch
public void writeUsers()
{
try{
File userFile = new File("Users.txt");
PrintWriter output = new PrintWriter(userFile);
for(User i: userList) {
output.append("Name:");
output.println(i.getrealName());
output.append("UID:");
output.println(i.getidName());
output.append("Password:");
output.println(i.getpassword());
output.println(" ");
}
output.close();
System.out.print("Information has been saved to Users.txt\n");
}
catch(FileNotFoundException fnf) {
System.err.println("FileNotFoundException: File Users.txt does not exist " + fnf);
}
catch(IOException eyeoh) {
System.err.println("IOException: Error writing to Users.txt " + eyeoh);
}
}