Here you can find the source of zipFile(String filePath, String fileName)
public static void zipFile(String filePath, String fileName) throws Exception
//package com.java2s; //License from project: Apache License import java.io.*; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static void zipFile(String filePath, String fileName) throws Exception { String[] filenames = new String[] { fileName }; byte[] buf = new byte[1024]; String outFilename = fileName + ".zip"; ZipOutputStream out = new ZipOutputStream(new FileOutputStream(filePath + "/" + outFilename)); for (int i = 0; i < filenames.length; ++i) { FileInputStream in = new FileInputStream(filePath + "/" + filenames[i]); out.putNextEntry(new ZipEntry(filenames[i])); boolean len = false; int var9; while ((var9 = in.read(buf)) > 0) { out.write(buf, 0, var9); }/*ww w . j a va 2 s . c o m*/ out.closeEntry(); in.close(); } out.close(); } }