Here you can find the source of zipFile(File inputFile, File outputZip)
public static void zipFile(File inputFile, File outputZip)
//package com.java2s; //License from project: Open Source License import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static void zipFile(File inputFile, File outputZip) { byte[] buffer = new byte[1024]; try {/*from www.j a va2 s . c om*/ FileOutputStream fos = new FileOutputStream(outputZip); ZipOutputStream zos = new ZipOutputStream(fos); ZipEntry ze = new ZipEntry(inputFile.getName()); zos.putNextEntry(ze); FileInputStream in = new FileInputStream(inputFile); int len; while ((len = in.read(buffer)) > 0) { zos.write(buffer, 0, len); } in.close(); zos.closeEntry(); zos.close(); } catch (Exception e) { e.printStackTrace(); } } }