too many entries in ZIP file

I am trying to write a Java class to extract a large zip file containing ~74000 XML files. I get the following exception when attempting to unzip it utilizing the java zip library: too many entries in ZIP file

Unfortunately due to requirements of the project I can not get the zip broken down before it gets to me, and the unzipping process has to be automated (no manual steps). Is there any way to get around this limitation utilizing or with some 3rd party Java zip library?



Using ZipInputStream instead of ZipFile should probably do it.

Using apache IOUtils:

FileInputStream fin = new FileInputStream(zip);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;

while ((ze = zin.getNextEntry()) != null) {
    FileOutputStream fout = new FileOutputStream(new File(
                    outputDirectory, ze.getName()));

    IOUtils.copy(zin, fout);



The Zip standard supports a max of 65536 entries in a file. Unless the Java library supports ZIP64 extensions, it won't work properly if you are trying to read or write an archive with 74,000 entries.

I reworked the method to deal with directory structures more convenient and to zip a whole bunch of targets at once. Plain files will be added to the root of the zip file, if you pass a directory, the underlying structure will be preserved.

def zip (String zipFile, String [] filesToZip){ 
    def result = new ZipOutputStream(new FileOutputStream(zipFile))
    result.withStream { zipOutStream ->
        filesToZip.each {fileToZip ->
            ftz = new File(fileToZip)
                pathlength = new File(ftz.absolutePath).parentFile.absolutePath.size()
                ftz.eachFileRecurse {f ->               
                    if(!f.isDirectory()) writeZipEntry(f, zipOutStream, f.absolutePath[pathlength..-1]) 
            else writeZipEntry(ftz, zipOutStream, '')

def writeZipEntry(File plainFile, ZipOutputStream zipOutStream, String path) {
    zipOutStream.putNextEntry(new ZipEntry(
    new FileInputStream(plainFile).withStream { inStream ->
        def buffer = new byte[1024]
        def count
        while((count =, 0, 1024)) != -1) 

Need Your Help

Can I prevent mobile safari from auto-rotating the screen on ipod touch or iphone?

iphone safari ipod-touch

We have an offline Safari application with UI designed for vertical use (pixel perfect). We would like the UI to stay vertical no matter what how the user rotates the ipod / iphone. Is it possible ...

How to avoid servlet responding with new html page?

java html jsp servlets

Following are my get() and post() method of my servlet. I am very new to servlet. When I call from my client, this servlet create a new page and overwrite all my html elements in my client. What I ...