使用可运行jar将数据保存到txt文件
你好, 我不知道如何制作它,以便将数据保存到txt。它在eclipse中工作,但在作为可运行Jar文件导出时不起作用 我的代码是:使用可运行jar将数据保存到txt文件,jar,save,runnable,Jar,Save,Runnable,你好, 我不知道如何制作它,以便将数据保存到txt。它在eclipse中工作,但在作为可运行Jar文件导出时不起作用 我的代码是: public void openFile() File file = new File(System.getProperty("user.dir"), "src/save/Kube.txt"); FileWriter fw = null; try { fw = new FileWriter(file.getAbsoluteFi
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中运行时,它可以正常工作,但当生成可运行的jar文件时不会保存。
谢谢你的帮助