Here you can find the source of saveZip(String fileName, Map
public static void saveZip(String fileName, Map<String, InputStream> dataMap)
//package com.java2s; import java.io.BufferedInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; public class Main { public static void saveZip(String fileName, Map<String, InputStream> dataMap) { try {/*from www .j av a 2 s.c o m*/ FileOutputStream fos = new FileOutputStream(fileName); JarOutputStream jos = new JarOutputStream(fos); byte buf[] = new byte[256]; if (dataMap != null) { Set<Entry<String, InputStream>> entrySet = dataMap.entrySet(); int len = -1; for (Entry<String, InputStream> entry : entrySet) { String name = entry.getKey(); InputStream inputStream = entry.getValue(); if (name != null && inputStream != null) { BufferedInputStream bis = new BufferedInputStream(inputStream); JarEntry jarEntry = new JarEntry(name); jos.putNextEntry(jarEntry); while ((len = bis.read(buf)) >= 0) { jos.write(buf, 0, len); } bis.close(); jos.closeEntry(); } } } jos.flush(); jos.close(); fos.flush(); fos.close(); } catch (Exception ex) { throw new RuntimeException(ex); } } }