Here you can find the source of zipFile(File zipfile, ZipOutputStream zos, String name)
static void zipFile(File zipfile, ZipOutputStream zos, String name) throws IOException
//package com.java2s; /*//from ww w . j ava2s .c o m * Copyright (C) 2011 Peransin Nicolas. * Use is subject to license terms. */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static final int BUFFER_SIZE = 2156; public static final boolean DEBUG = false; static void zipFile(File zipfile, ZipOutputStream zos, String name) throws IOException { // if we reached here, the File object f was not a directory // create a FileInputStream on top of f FileInputStream fis = new FileInputStream(zipfile); try { // create a new zip entry ZipEntry anEntry = new ZipEntry(name); if (DEBUG) System.out.println("Add file : " + name); // place the zip entry in the ZipOutputStream object zos.putNextEntry(anEntry); // now write the content of the file to the // ZipOutputStream byte[] readBuffer = new byte[BUFFER_SIZE]; for (int bytesIn = fis.read(readBuffer); bytesIn != -1; bytesIn = fis.read(readBuffer)) { zos.write(readBuffer, 0, bytesIn); } } finally { // close the Stream fis.close(); } } }