使用 Java 压缩文件:有限制吗?
我正在使用 Java 为我的应用程序创建一个备份例程。 但是,当 zip 文件超过 4GB 或包含超过 65,000 个文件(大约)时,zip 文件就会损坏。
我还在测试 Apache Commons Compression 以压缩为 tar.gz,但它的文件名限制为 100 个字符。 我想测试这个 API 压缩为 zip,但我想知道 java zip 到底有什么问题。
所以,真正的问题是:我做错了什么,这是 Java Zip 实现的限制,还是 Zip 格式本身的限制?
谢谢。
I'm creating a backup routine for my application with Java.
However, when the zip file is over 4GB, or has more than 65,000 files (approximately), the zip file is corrupted.
I'm also testing the Apache Commons Compression for compacting to tar.gz, but it has file name limit of 100 characters.
I was wanting to test this API compressing to zip, but I wonder what exactly is the problem with the java zip.
So, the real question is: I'm doing something wrong, it is limit of Java Zip implementation, or is the limit for the Zip format itself?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
引用自维基百科:
关于 ZIP64:
Quoting from Wikipedia:
and about ZIP64:
据报告,该错误已在 Java 7 中修复: https://bugs.java.com/ bugdatabase/view_bug?bug_id=4681995
该票证的评论者之一提到 TrueZIP 作为解决方法。
It's a bug that's reported fixed in Java 7: https://bugs.java.com/bugdatabase/view_bug?bug_id=4681995
One of the commenters on that tickets mentions TrueZIP as a workaround.
标准 Zip 文件的文件大小限制为 4GB。
有关更多信息,请参阅关于 zip 文件的维基百科条目......显然,如果您使用 ZIP64 格式,您可以获得更大的文件。
ps 如果您发现自己尝试一次备份超过 4GB 的数据,也许您应该考虑采用不同的方法?也许采用版本化文件系统快照的东西会更合适?
There's a 4GB file size limit on standard Zip files.
See the wikipedia entry on zip files for some more info...... apparently you can get much much larger files if you use ZIP64 format.
p.s. if you find yourself trying to back up more than 4GB of data at a time, perhaps you should be considering a different approach? Maybe something that takes a versioned filesystem snapshot would be more appropriate?
是的,有一个限制。如果您像这样浏览条目,
则会计数到 65535 个条目,仅此而已。
Yes, there is a limit. If you go through the entries like
it will count up until 65535 entries and no more.