Here you can find the source of zipDir(String dir, ZipOutputStream zos)
public static void zipDir(String dir, ZipOutputStream zos) throws IOException
//package com.java2s; /*/*from ww w . j a v a 2s. c o m*/ * Copyright 2010-2011, Sikuli.org * Released under the MIT License. * */ import java.io.*; import java.util.zip.*; public class Main { public static void zipDir(String dir, ZipOutputStream zos) throws IOException { File zipDir = new File(dir); String[] dirList = zipDir.list(); byte[] readBuffer = new byte[1024]; int bytesIn; for (int i = 0; i < dirList.length; i++) { File f = new File(zipDir, dirList[i]); /* if(f.isDirectory()) { String filePath = f.getPath(); zipDir(filePath, zos); continue; } */ if (f.isFile()) { FileInputStream fis = new FileInputStream(f); ZipEntry anEntry = new ZipEntry(f.getName()); zos.putNextEntry(anEntry); while ((bytesIn = fis.read(readBuffer)) != -1) { zos.write(readBuffer, 0, bytesIn); } fis.close(); } } } public static String getName(String filename) { File f = new File(filename); return f.getName(); } }