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: , ,