Today I've finished my game, but there's a problem. There're more than 500+ images in my resources folder and I want to compress them into a single file, like other games do (for example put everything in a .pak file). I've searched on the internet, but I can't find something that tells about how to do it with Java.

There's maybe a library that I can use to avoid that problem?


  • \$\begingroup\$ Is this for deployment purposes? Will the files be uncompressed when the game is installed, or will the game load the files directly from the compressed package? \$\endgroup\$
    – KaareZ
    Aug 1, 2015 at 13:24
  • \$\begingroup\$ Yes, it is. I don't want others to modify easily the resources. @KaareZ \$\endgroup\$ Aug 1, 2015 at 13:44
  • \$\begingroup\$ Then I don't know much about it. You could also try to put your resources inside the jar? \$\endgroup\$
    – KaareZ
    Aug 1, 2015 at 13:57
  • \$\begingroup\$ I've tried it, but you can decompile it and get all the files. \$\endgroup\$ Aug 1, 2015 at 14:00
  • \$\begingroup\$ @KaareZ What would stop you from opening the .jar with win rar and viewing the images then ? \$\endgroup\$
    – dimitris93
    Aug 1, 2015 at 14:12

1 Answer 1


Put all of the resources in a ZIP archive.

Rename the file from example.zip to example.pak (or whatever else you want).

Lastly, uncompress the archive and load all of your resources.

ZipFile zipFile = new ZipFile("/external/path/to/test.zip");

Enumeration<? extends ZipEntry> entries = zipFile.entries();

    ZipEntry entry = entries.nextElement();
    InputStream stream = zipFile.getInputStream(entry);

You can also read an archive from inside of your JAR file.

URL url = new URL("jar:file:/path/of/file.jar!/resources.pak");

The location of the running JAR can be easily retrieved (as long as the class that this is called from has been loaded from that JAR).

new File(MyClass.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
  • \$\begingroup\$ Perfect solution to my problem. I raccomand it! \$\endgroup\$ Oct 2, 2015 at 13:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .