Here you can find the source of addToZip(File input, String entryName, ZipOutputStream zos, boolean withHidden, Set
private static void addToZip(File input, String entryName, ZipOutputStream zos, boolean withHidden, Set<String> excludeEntries) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { private static void addToZip(File input, String entryName, ZipOutputStream zos, boolean withHidden, Set<String> excludeEntries) throws IOException { if (input.isHidden() && !withHidden) return; if (input.isDirectory()) { if (entryName.length() > 0) entryName += "/"; for (File f : input.listFiles()) addToZip(f, entryName + f.getName(), zos, withHidden, excludeEntries); } else if (input.isFile()) { if (excludeEntries != null && excludeEntries.contains(entryName)) return; FileInputStream fis = null; try { byte[] buffer = new byte[10000]; fis = new FileInputStream(input); zos.putNextEntry(new ZipEntry(entryName)); int length; while ((length = fis.read(buffer)) > 0) zos.write(buffer, 0, length); zos.closeEntry();/*w ww.ja v a 2s . co m*/ } finally { try { if (fis != null) fis.close(); } catch (Exception ignore) { } } } } }