Java zipEntry.getSize() returns the size of the actual file and some times it returns -1 (though the file size is greater than 0).
Java API document says "Returns the uncompressed size of the entry data, or -1 if not known."
Not sure on what situation it will return -1 i.e. on what situation it will be unknown?
Surprisely using ZipFile instead of ZipInputStream for getting the entries makes getSize and getCompressedSize to return the right values.
ZipFile zipfile = new ZipFile("myFile.zip");
java.util.Enumeration zipEnum = zipfile.entries();
while (zipEnum.hasMoreElements ())
{
ZipEntry entry = (ZipEntry) zipEnum.nextElement();
if (! entry.isDirectory ())
{
// entry.getName()
// entry.getSize ()
// entry.getCompressedSize ()
}
}
trick found at http://vimalathithen.blogspot.de/2006/06/using-zipentrygetsize.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With