Here you can find the source of zipFiles(String output, String sDir, String sSearch)
public static void zipFiles(String output, String sDir, String sSearch) throws Exception
//package com.java2s; import java.io.*; import java.util.zip.*; import java.util.List; import java.util.ArrayList; public class Main { public static void zipFiles(String output, String sDir, String sSearch) throws Exception { File dir = new File(sDir).getCanonicalFile(); ;/* w w w. j a va 2 s .c o m*/ File[] files = dir.listFiles(); List<File> lst = new ArrayList<File>(); for (File f : files) { if (sSearch.equals("*")) { lst.add(f); } else if (sSearch.indexOf("*.") >= 0) { if (f.getName().indexOf(sSearch.substring(sSearch.indexOf(".") + 1)) >= 1) { lst.add(f); } } } if (lst.size() > 0) { ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(output)); zipOut.setLevel(Deflater.DEFAULT_COMPRESSION); for (File f : lst) { zipFile(zipOut, sDir, f); } zipOut.close(); } } public static void zipFile(ZipOutputStream zipOut, String path, File file) throws IOException { if (!file.canRead()) { System.out.println("Cannot read " + file.getCanonicalPath() + " (maybe because of permissions)"); return; } System.out.println("Compressing " + file.getName()); zipOut.putNextEntry(new ZipEntry(file.getName())); FileInputStream fis = new FileInputStream(file); byte[] buffer = new byte[4092]; int byteCount = 0; while ((byteCount = fis.read(buffer)) != -1) { zipOut.write(buffer, 0, byteCount); System.out.print('.'); System.out.flush(); } System.out.println(); fis.close(); zipOut.closeEntry(); } }