Here you can find the source of zip(String[] srcFiles, String dstFile, String comment)
public static void zip(String[] srcFiles, String dstFile, String comment) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static void zip(String[] srcFiles, String dstFile, String comment) throws IOException { if (srcFiles.length == 0) { return; }// www.j av a 2s .c o m File fileDst = new File(dstFile); File parentDir = fileDst.getParentFile(); if (!parentDir.exists()) { parentDir.mkdirs(); } if (fileDst.exists()) { fileDst.delete(); } fileDst.createNewFile(); ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(fileDst)); zos.setMethod(ZipOutputStream.DEFLATED); if (comment != null) { zos.setComment(comment); } DataOutputStream dos = new DataOutputStream(zos); for (int i = 0; i < srcFiles.length; i++) { String entryPath = srcFiles[i]; zos.putNextEntry(new ZipEntry(entryPath)); File fileEntry = new File(entryPath); FileInputStream fis = new FileInputStream(fileEntry); byte[] buff = new byte[8192]; int len = 0; while (true) { len = fis.read(buff); if (len == -1 || len == 0) { break; } dos.write(buff, 0, len); } zos.closeEntry(); fis.close(); } dos.close(); zos.close(); } public static void zip(String[] srcFiles, String dstFile) throws IOException { zip(srcFiles, dstFile, null); } }