Apr 14
// Create the ZIP file

ZipOutputStream out = new ZipOutputStream(new FileOutputStream("my.zip"));

// loop through the files to add to zip

for (int i=0; i<filenames.length; i++)
{
	// open file

    FileInputStream in = new FileInputStream(filenames[i]);

    // Add new entry to zip

    out.putNextEntry(new ZipEntry(filenames[i]));

    // copy file to zip
    // see http://helpdesk.objects.com.au/java/how-do-i-copy-one-stream-to-another-using-java

    int len;
    while ((len = in.read(buf)) >= 0)
    {
        out.write(buf, 0, len);
    }

    // Close the entry and file

    out.closeEntry();
    in.close();
}

// Close the ZIP file

out.close();

written by objects \\ tags: , ,

Dec 13

If you get the following error when trying to read a valid zip file using Java it may be because it contains an entry larger than 4gb.

java.util.zip.ZipException: invalid CEN header

Java’s implementation of Java only support entries smaller than 4gb. To read a zip file that contains entries larger than 4gb you will need to use a 3rd pary implementation such as Zip64

written by objects \\ tags: , , ,