开发者

Zip files with Java: Is there a limit?

开发者 https://www.devze.com 2023-03-21 17:55 出处:网络
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 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 pro开发者_StackOverflow社区blem 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.


Quoting from Wikipedia:

The original ZIP format had a 4 GiB limit on various things (uncompressed size of a file, compressed size of a file and total size of the archive), as well as a limit of 65535 entries in a ZIP archive.

and about ZIP64:

Java's built-in java.util.zip does not support it as of September 2010, but it has been added to OpenJDK and is planned for inclusion in Java 7.


It's a bug that's reported fixed in Java 7: http://bugs.sun.com/view_bug.do?bug_id=4681995

One of the commenters on that tickets mentions TrueZIP as a workaround.


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?


Yes, there is a limit. If you go through the entries like

        int count  = 0;
        for (Enumeration<? extends ZipEntry> e = zipFile.entries(); e.hasMoreElements(); ) {
            final ZipEntry ze = e.nextElement();
            count++;
        }

it will count up until 65535 entries and no more.

0

精彩评论

暂无评论...
验证码 换一张
取 消