Here you can find the source of zip(File directory, File base, ZipOutputStream zos, byte[] buffer)
public static final void zip(File directory, File base, ZipOutputStream zos, byte[] buffer) 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 final void zip(File directory, File base, ZipOutputStream zos, byte[] buffer) throws IOException { int read = 0; for (File file : directory.listFiles()) { if (file.isDirectory()) { zip(file, base, zos, buffer); } else { FileInputStream in = new FileInputStream(file); try { ZipEntry entry = new ZipEntry(file.getPath().substring(base.getPath().length() + 1)); zos.putNextEntry(entry); while ((read = in.read(buffer)) > -1) { zos.write(buffer, 0, read); }// w ww.j a v a 2 s . c o m } finally { in.close(); } } } } public static final void zip(File directory, File zip) throws IOException { byte[] buffer = new byte[8192]; FileOutputStream fos = new FileOutputStream(zip); ZipOutputStream zos = new ZipOutputStream(fos); try { zip(directory, directory, zos, buffer); } finally { zos.close(); fos.close(); } } }