Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.util.Iterator; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { private static byte[] createZip(Map<String, byte[]> files) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ZipOutputStream zf = new ZipOutputStream(bos); Iterator<String> it = files.keySet().iterator(); String fileName = null; ZipEntry ze = null; while (it.hasNext()) { fileName = it.next(); ze = new ZipEntry(fileName); zf.putNextEntry(ze); zf.write(files.get(fileName)); } zf.close(); return bos.toByteArray(); } }