Here you can find the source of zipFolder(String sourceDir, String destDir, String name)
public static void zipFolder(String sourceDir, String destDir, String name) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static void zipFolder(String sourceDir, String destDir, String name) throws IOException { FileOutputStream fos = new FileOutputStream(destDir + "/" + name + ".zip"); ZipOutputStream zipOut = new ZipOutputStream(fos); File fileToZip = new File(sourceDir); zipFile(fileToZip, fileToZip.getName(), zipOut); zipOut.close();// w ww. j av a 2 s.c o m fos.close(); } private static void zipFile(File fileToZip, String fileName, ZipOutputStream zipOut) throws IOException { if (fileToZip.isHidden()) { return; } if (fileToZip.isDirectory()) { File[] children = fileToZip.listFiles(); for (File childFile : children) { zipFile(childFile, fileName + "/" + childFile.getName(), zipOut); } return; } FileInputStream fis = new FileInputStream(fileToZip); ZipEntry zipEntry = new ZipEntry(fileName); zipOut.putNextEntry(zipEntry); byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zipOut.write(bytes, 0, length); } fis.close(); } }