0

I'm trying to add files to a .jar file.
My problem is that JarOutputStream the old .jar file overwrites.

So I created this code:

Enumeration<JarEntry> enu = game.entries()
while(enu.hasMoreElements()){
    File f = doThing(game.getInputStream(enu.nextElement()));
    add(f,os);
}

game is a JarFile.
add(File, JarOutputStream) adds a file to the JarOutputStream and os is a JarOutputStream.

But if I try this code i get this error:

Exception in thread "AWT-EventQueue-0" java.util.zip.ZipError: jzentry == 0,
 jzfile = 576741376,
 total = 57,
 name = C:\Users\Jorolf\Desktop\XXX.jar,
 i = 1,
 message = null

(I get the error when calling enu.nextElement())

Edit:
I was reading and writing the same file at the same time so I changed it so I write to a temporary file and afterwards replace the old file with the temporary.

Jorolf
  • 50
  • 8
  • `My problem is that JarOutputStream the old .jar file overwrites. ` Do you mean you are trying to write the file that you are reading at the same time? – copeg Jul 13 '16 at 20:21
  • @copeg not at the same time. It should read all Files from the jar file and then write everything to the new one.( At the end I'm doing os.close()) – Jorolf Jul 13 '16 at 21:47
  • `At the end I'm doing os.close()` Still unclear, and still sounds like you are writing at the same time (just because `os.close` is not called doesn't mean it won't be writing). I recommend posting an [MCVE](http://stackoverflow.com/help/mcve) to clear up any assumptions that may or may not be made – copeg Jul 13 '16 at 22:00

0 Answers0