ZipException creating zip file

I am trying to modify a zip file, by creating a new zip file and copying the entries over selectively. I use the following code:

try

{

zipFile = new ZipFile(args[0]);

zos = new ZipOutputStream(new FileOutputStream(args[1]));

entries = zipFile.entries();

while(entries.hasMoreElements())

{

entry = (ZipEntry)entries.nextElement();

if (entry.getName().endsWith(".class") || entry.isDirectory() ||

entry.getName().endsWith(".MF"))

{

zos.putNextEntry(entry);

}

}

zipFile.close();

zos.close();

}

catch (IOException ioe)

{

System.err.println("Unhandled exception:");

ioe.printStackTrace();

System.err.println(entry);

return;

}

However it throws an exception for the second entry that it encounters:

invalid entry size (expected 10804 but got 0 bytes)

at java.util.zip.ZipOutputStream.closeEntry(Unknown Source)

at java.util.zip.ZipOutputStream.putNextEntry(Unknown Source)

at delPNGsFromJar.main(delPNGsFromJar.java:34)

It doesn't matter which entry it is, it always fails on the seconds.

Anyone have any ideas?

[1203 byte] By [CaptainFreedoma] at [2007-11-27 4:25:12]
# 1

A ZipEntry only contains data associated with the entry, it does not contain any actual data. In addition to putting an entry with "putNextEntry" you have to write its data.

You do this by getting the entry's InputStream from the ZipFile object, and writing what you read from it to the ZipOutputStream. Don't forget to close the entry when you're done.

jsalonena at 2007-7-12 9:33:17 > top of Java-index,Java Essentials,Java Programming...