0
我在做一個hang子手遊戲,目標是保存不同玩家的屬性,比如他們的名字,玩過的遊戲和勝利。我有這部分工作,但每次運行該程序它刪除以前的數據並將其替換。Java PrintWriter:隨着時間的推移寫入相同的文件
public static void writeStats(File file,String name, int won, int games) {
try {
PrintWriter pw = new PrintWriter(file);
pw.println("Player\tWon\tTotal");
pw.println("-----------------------------");
pw.println(name+"\t"+won+"\t"+games);
pw.close();
} //end try
catch (IOException e) {
System.out.println("Failed to write file!");
} //end catch
} //end method
[如何將文本追加到Java中的現有文件](http://stackoverflow.com/questions/1625234/how-to-append-text-to-an-existing-file-in-java) – Tom