简体   繁体   中英

Write a file into Java archive (JAR)

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

在此处输入图片说明

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).

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM