使用可运行的jar将数据保存到txt文件

时间:2015-01-11 09:04:08

标签: jar save runnable


您好,

我无法找到如何制作它以便我可以将数据保存到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文件无法保存。 谢谢你的帮助!

0 个答案:

没有答案