Here you can find the source of addToZip(String[] sourceFiles, ZipOutputStream output)
private static void addToZip(String[] sourceFiles, ZipOutputStream output) throws FileNotFoundException, IOException
//package com.java2s; /**//from w w w.j ava 2 s .co m * Aptana Studio * Copyright (c) 2005-2012 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions). * Please see the license.html included with this distribution for details. * Any modifications to this file must keep this entire header intact. */ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.zip.ZipOutputStream; public class Main { private static void addToZip(String[] sourceFiles, ZipOutputStream output) throws FileNotFoundException, IOException { byte[] buffer = new byte[1024]; for (String file : sourceFiles) { File content = new File(file); if (content.isDirectory()) { File[] children = content.listFiles(); String[] childrenPaths = new String[children.length]; for (int i = 0; i < children.length; i++) { childrenPaths[i] = children[i].getAbsolutePath(); } addToZip(childrenPaths, output); } else if (content.canRead()) { FileInputStream input = new FileInputStream(file); output.putNextEntry(new java.util.zip.ZipEntry(file)); int length; while ((length = input.read(buffer)) > 0) { output.write(buffer, 0, length); } output.closeEntry(); input.close(); } } } }