【发布时间】:2017-11-10 02:47:36
【问题描述】:
所以我正在制作一个游戏并尝试添加一个读取文本文件中某些数据的高分表。如果用户以前从未玩过游戏或文件不存在,则动态创建文本文件。我可以成功创建此文件,但由于某种原因,PrintWriter 不会写入该文件。谁能解释一下原因?
//VARIABLE DECLARATIONS
String currentDirectory = System.getProperty("user.dir"); //Contains the current directory the program is located in.
File forTable = new File(currentDirectory + "\\highScoreTable.txt");
PrintWriter updateTable = new PrintWriter(new FileWriter(forTable), true);
if(!forTable.exists())
{
forTable.createNewFile();
updateTable.println("Player\t\tScore");
updateTable.println("-------\t\t--");
updateTable.println("-------\t\t--");
updateTable.println("-------\t\t--");
updateTable.println("-------\t\t--");
updateTable.println("-------\t\t--");
}
updateTable.close(); //Close the print writer
【问题讨论】:
标签: java io printwriter