Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Storing a jar in a ZipOutputStream results in jar corruption

807606Apr 20 2007 — edited Apr 20 2007
Hi, I need to create a zip archive with the following structure:
archive.zip
  |_folder
          |_subarchive.zip
                         |_file.jad
                         |_file.jar
I use the following code:
zout = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(newPackage)));
zout.putNextEntry(new ZipEntry("folder/"));
zout.putNextEntry(new ZipEntry("folder/subarchive.zip"));

//Copy the jar
ZipOutputStream ztemp = new ZipOutputStream(zout);
BufferedReader cbr = new BufferedReader(new FileReader(new File(srcFolder,"file.jar")));
ZipEntry jarEntry = new ZipEntry("file.jar");
ztemp.putNextEntry(jarEntry);
int read = 0;
BufferedReader cbr = new BufferedReader(new FileReader(new File(srcFolder,"file.jar")));
while((read = cbr.read(buffer,0,buffer.length)) > 0)
    ztemp.write(toByteArray(buffer),0,read);
cbr.close();
ztemp.closeEntry();

//Copy the jad
ztemp.putNextEntry(new ZipEntry("file.jad"));
cbr = new BufferedReader(new FileReader(new File(srcFolder,"file.jad")));
read = 0;
while((read = cbr.read(buffer,0,buffer.length)) >= 0)
    ztemp.write(toByteArray(buffer),0,read);
cbr.close();
ztemp.closeEntry();
ztemp.finish();
zout.close();
The archive is created withe the correct structure, when i extract it to test it i see that the jad is ok, and If i open the jar with winrar it contains the correct structure (the same as the original jar), but if I try to extract it I get CRC errors for every file in the archive and the jar results corrupted... how can I solve this?
Thanks bye.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 18 2007
Added on Apr 20 2007
3 comments
208 views