简体   繁体   English

使用java.util.zip写入大小

[英]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 我注意到使用java.util.zip库创建.zip文件时无法正确写入大小,因此

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

both always return -1 . 两者总是返回-1

This doesn't happen if I create zipEntry with a ZipFile and Enumeration - which I can't do in this particular case. 如果我使用ZipFileEnumeration创建zipEntry ,则不会发生这种情况,在这种情况下我无法做到。

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. 我认为问题并非来自您调用库的方式,而可能来自您的zip文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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