0

I would like to write a file into Java archive (JAR). What do I need to modify in my code?

enter image description here

private void menu_savegame(ActionEvent e) {
    File config = new File("config");
    try {
        FileWriter fw = new FileWriter(config);
        fw.append(Integer.toString(level.current));
        fw.append("\n");
        if (win){
            fw.append(Integer.toString(ballCount));
        }
        else{
            fw.append(Integer.toString(G));
        }
        fw.append("\n");
        fw.append(Integer.toString(liveLeft));
        fw.flush();
    } catch (IOException e1) {
        e1.printStackTrace();
    }

}

I just would like this file to be written not to the folder, but into the Game.jar file - I have there all the game resources (images).

Honza Zidek
  • 9,204
  • 4
  • 72
  • 118
Aero
  • 19
  • 1
  • 7

1 Answers1

0

Dont forget that JAR is a typical ZIP file. In provided link you can see how it is performed.

zip manipulation with java

eventually, use external libraries like JBoss ShrinkWrap.

here's link to api

good luck!

Community
  • 1
  • 1
Miron Balcerzak
  • 886
  • 10
  • 21