Here you can find the source of zip(List
public static void zip(List<File> runtimeLibFiles, File saturnContainerDir, File zipFile) 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.List; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { private static final String fileSeparator = System.getProperty("file.separator"); public static void zip(List<File> runtimeLibFiles, File saturnContainerDir, File zipFile) throws IOException { ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile)); /* for(File file : saturnContainerDir.listFiles()) { zip(file, "saturn", zos);//from w w w. j a v a 2 s .co m }*/ for (File file : runtimeLibFiles) { zip(file, "app" + fileSeparator + "lib", zos); } zos.close(); } private static void zip(File file, String parent, ZipOutputStream zos) throws IOException { if (file == null || !file.exists()) return; if (file.isFile()) { String entryName = parent == null ? file.getName() : parent + fileSeparator + file.getName(); zos.putNextEntry(new ZipEntry(entryName)); FileInputStream fis = new FileInputStream(file); int len = -1; byte[] bs = new byte[2048]; while ((len = fis.read(bs, 0, 2048)) != -1) { zos.write(bs, 0, len); } fis.close(); } else if (file.isDirectory()) { String entryName = parent == null ? file.getName() : parent + fileSeparator + file.getName(); zos.putNextEntry(new ZipEntry(entryName + "/")); File[] listFiles = file.listFiles(); if (listFiles != null) { for (File tmp : file.listFiles()) { zip(tmp, entryName, zos); } } } } }