您好,
我无法找到如何制作它以便我可以将数据保存到txt。它在我日食期间工作,但在我作为可运行的Jar文件导出时不起作用。
我的代码是:
public void openFile()
File file = new File(System.getProperty("user.dir"), "src/save/Kube.txt");
FileWriter fw = null;
try {
fw = new FileWriter(file.getAbsoluteFile());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
x = new BufferedWriter(fw);
}
public void addRecords() {
try {
x.write(game.getTotalCoins() + "\n");
x.write(game.getHighScore() + "\n");
x.write(game.getBackround() + "\n");
x.write(game.getCube() + "\n");
x.write(game.isBlackselected() + "\n");
x.write(game.isBlueselected() + "\n");
x.write(game.isGreenselected() + "\n");
x.write(game.isBlueunlocked() + "\n");
x.write(game.isGreenunlocked() + "\n");
x.write(game.isDefaultselected() + "\n");
x.write(game.isSkyselected() + "\n");
x.write(game.isUnderwaterselected() + "\n");
x.write(game.isSkyunlocked() + "\n");
x.write(game.isUnderwaterunlocked() + "");
} catch (IOException e) {
e.printStackTrace();
}
}
public void closeFile() {
try {
x.close();
} catch (IOException e) {
e.printStackTrace();
}
}
在eclipse中运行时它工作正常但是当制作成runnable时,jar文件无法保存。 谢谢你的帮助!