Here you can find the source of addToZipFile(String fileName, ZipOutputStream zos)
public static void addToZipFile(String fileName, ZipOutputStream zos) throws FileNotFoundException, IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static void addToZipFile(String fileName, ZipOutputStream zos) throws FileNotFoundException, IOException { System.out.println("Writing '" + fileName + "' to zip file"); File file = new File(fileName); FileInputStream fis = new FileInputStream(file); ZipEntry zipEntry = new ZipEntry(file.getName()); zos.putNextEntry(zipEntry);/*from w w w . j av a 2s . co m*/ byte[] bytes = new byte[1024]; int length; while ((length = fis.read(bytes)) >= 0) { zos.write(bytes, 0, length); } zos.closeEntry(); fis.close(); } }