【发布时间】:2015-10-05 03:02:20
【问题描述】:
我正在制作一个刽子手游戏,目标是保存不同玩家的统计数据,例如他们的姓名、玩过的游戏和获胜次数。我有这部分工作,但每次我运行程序时,它都会删除以前的数据并替换它。
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 file-io printwriter