Here you can find the source of zip(final File zipFile, final File... files)
private static void zip(final File zipFile, final File... files) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { private static final int BUFFER = 2048; private static void zip(final File zipFile, final File... files) throws IOException { try (final FileOutputStream fos = new FileOutputStream(zipFile); final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos))) { final byte[] data = new byte[BUFFER]; for (final File file : files) { try (final FileInputStream fis = new FileInputStream(file); final BufferedInputStream origin = new BufferedInputStream(fis, BUFFER)) { final ZipEntry entry = new ZipEntry(file.getName()); zos.putNextEntry(entry); int readCount; while ((readCount = origin.read(data, 0, BUFFER)) != -1) { zos.write(data, 0, readCount); }// w ww . j a va 2s. co m } } } } }