Here you can find the source of zipFiles(File[] listFiles2Zip, File output)
public static void zipFiles(File[] listFiles2Zip, File output) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static void zipFiles(File[] listFiles2Zip, File output) throws IOException { // These are the files to include in the ZIP file // Create a buffer for reading the files byte[] buf = new byte[1024]; // Create the ZIP file ZipOutputStream out = new ZipOutputStream(new FileOutputStream(output)); // Compress the files for (File actualFile : listFiles2Zip) { FileInputStream in = new FileInputStream(actualFile); // Add ZIP entry to output stream. out.putNextEntry(new ZipEntry(actualFile.getName())); // Transfer bytes from the file to the ZIP file int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len);// w w w. j a va 2 s . c om } // Complete the entry out.closeEntry(); in.close(); } // Complete the ZIP file out.close(); } }