Here you can find the source of zip(File zipFile, List
public static File zip(File zipFile, List<File> files) throws FileNotFoundException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.util.List; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static File zip(File zipFile, List<File> files) throws FileNotFoundException { ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFile)); zip(out, files);/*from w w w.ja v a 2s.c o m*/ return zipFile; } public static void zip(ZipOutputStream out, List<File> srcFiles) { try { for (File srcFile : srcFiles) { zip(out, srcFile); } out.close(); } catch (Exception e) { e.printStackTrace(); } } public static void zip(ZipOutputStream out, File srcFile) throws IOException { out.putNextEntry(new ZipEntry(srcFile.getName())); FileInputStream fis = new FileInputStream(srcFile); byte[] buffer = new byte[1024]; int length; while ((length = fis.read(buffer, 0, buffer.length)) != -1) { out.write(buffer, 0, length); } out.closeEntry(); fis.close(); } }