Here you can find the source of zipFile(final File target, final ZipOutputStream zip, final File file, final String path)
private static void zipFile(final File target, final ZipOutputStream zip, final File file, final String path) throws IOException
//package com.java2s; /****************************************************************************** * Copyright (c) 2008 Oracle//from w ww . j a v a 2s. c om * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Konstantin Komissarchik - initial implementation and ongoing maintenance ******************************************************************************/ 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 { private static void zipFile(final File target, final ZipOutputStream zip, final File file, final String path) throws IOException { if (!file.equals(target)) { final ZipEntry ze = new ZipEntry(path); ze.setTime(file.lastModified() + 1999); ze.setMethod(ZipEntry.DEFLATED); zip.putNextEntry(ze); final FileInputStream in = new FileInputStream(file); try { int bufsize = 8 * 1024; final long flength = file.length(); if (flength == 0) { return; } else if (flength < bufsize) { bufsize = (int) flength; } final byte[] buffer = new byte[bufsize]; int count = in.read(buffer); while (count != -1) { zip.write(buffer, 0, count); count = in.read(buffer); } } finally { try { in.close(); } catch (IOException e) { } } } } }