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.