简体   繁体   中英

Write size with java.util.zip

I noticed that creating a .zip file using the java.util.zip library doesn't write the size properly and because of that

zipEntry.getSize; //created with a ZipInputStream (zipEntry = zis.getNextEntry())
zipEntry.getCompressedSize();

both always return -1 .

This doesn't happen if I create zipEntry with a ZipFile and Enumeration - which I can't do in this particular case.

How do I make the library write the sizes properly?

I have tried the following code and returned sizes were good.

ZipInputStream zis = new ZipInputStream(new FileInputStream(new File("/tmp/foo.zip")));
ZipEntry entry = zis.getNextEntry();
System.out.println(entry.getSize());
System.out.println(entry.getCompressedSize());
zis.close();

I think the problem does not come from the way you call the library but might come from your zip file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM