Here you can find the source of zipFile(File file, File zipFile)
public static void zipFile(File file, File zipFile) throws Exception
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static void zipFile(File file, File zipFile) throws Exception { byte[] buffer = new byte[8192]; int read = 0; ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile)); FileInputStream fis = new FileInputStream(file); zos.putNextEntry(new ZipEntry(file.getName())); while ((read = fis.read(buffer)) > 0) { zos.write(buffer, 0, read);//from w ww . jav a 2 s . co m } fis.close(); zos.closeEntry(); zos.close(); } }