Here you can find the source of zipFiles(String files[], String fielPath)
public static byte[] zipFiles(String files[], String fielPath) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static byte[] zipFiles(String files[], String fielPath) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(bout); zos.setLevel(6);/*from www . j a va 2s . co m*/ byte[] bytes = new byte[10000]; for (int i = 0; i < files.length; i++) { FileInputStream fis = new FileInputStream(fielPath + "\\" + files[i]); BufferedInputStream bis = new BufferedInputStream(fis); zos.putNextEntry(new ZipEntry(files[i])); int bytesCount = -1; while ((bytesCount = bis.read(bytes)) != -1) { zos.write(bytes, 0, bytesCount); } zos.closeEntry(); bis.close(); fis.close(); } zos.flush(); bout.flush(); zos.close(); bout.close(); return bout.toByteArray(); } }