Here you can find the source of zipAutoBase(File f, File base, ZipOutputStream out)
private static void zipAutoBase(File f, File base, ZipOutputStream out) throws FileNotFoundException, IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { private static void zipAutoBase(File f, File base, ZipOutputStream out) throws FileNotFoundException, IOException { if (f.isDirectory()) { for (File file : f.listFiles()) { zipAutoBase(file, base, out); }/* w w w .ja va 2s .c o m*/ } else { String path = f.getPath().replace(base.getPath(), ""); if (path.startsWith(System.getProperty("file.separator"))) { path = path.substring(1); } path = path.replace(System.getProperty("file.separator"), "/"); FileInputStream fin = new FileInputStream(f); ZipEntry entry = new ZipEntry(path); out.putNextEntry(entry); byte[] buffer = new byte[8192]; int bytes_read = 0; while ((bytes_read = fin.read(buffer)) != -1) { out.write(buffer, 0, bytes_read); } fin.close(); } } }