Here you can find the source of zipFiles(ZipOutputStream out, String path, File... srcFiles)
public static void zipFiles(ZipOutputStream out, String path, File... srcFiles)
//package com.java2s; import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static void zipFiles(ZipOutputStream out, String path, File... srcFiles) { path = path.replaceAll("\\*", "/"); if (!path.endsWith("/")) { path += "/"; }//from www . j av a2 s . c o m byte[] buf = new byte[1024]; try { for (File srcFile : srcFiles) { if (srcFile.isDirectory()) { File[] files = srcFile.listFiles(); String srcPath = srcFile.getName(); srcPath = srcPath.replaceAll("\\*", "/"); if (!srcPath.endsWith("/")) { srcPath += "/"; } out.putNextEntry(new ZipEntry(path + srcPath)); zipFiles(out, path + srcPath, files); } else { try (FileInputStream in = new FileInputStream(srcFile)) { out.putNextEntry(new ZipEntry(path + srcFile.getName())); int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.closeEntry(); } } } } catch (Exception e) { e.printStackTrace(); } } }