Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用可运行jar将数据保存到txt文件_Jar_Save_Runnable - Fatal编程技术网

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

使用可运行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

你好,

我不知道如何制作它,以便将数据保存到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.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文件时不会保存。 谢谢你的帮助