Here you can find the source of zipFile(ZipOutputStream out, File sourceFile)
private static void zipFile(ZipOutputStream out, File sourceFile) throws IOException
//package com.java2s; /**/*from w w w .jav a2 s . c o m*/ * Copyright (c) 2015 SK holdings Co., Ltd. All rights reserved. * This software is the confidential and proprietary information of SK holdings. * You shall not disclose such confidential information and shall use it only in * accordance with the terms of the license agreement you entered into with SK holdings. * (http://www.eclipse.org/legal/epl-v10.html) */ import java.io.BufferedInputStream; 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 final int BUFFER = 2048; private static void zipFile(ZipOutputStream out, File sourceFile) throws IOException { System.out.println("Adding File: " + sourceFile.getAbsolutePath()); FileInputStream fi = new FileInputStream(sourceFile); BufferedInputStream origin = new BufferedInputStream(fi, BUFFER); String entryName = sourceFile.getAbsolutePath().substring(sourceFile.getAbsolutePath().indexOf(':') + 2, sourceFile.getAbsolutePath().length()); ZipEntry entry = new ZipEntry(entryName); out.putNextEntry(entry); int count; byte data[] = new byte[BUFFER]; while ((count = origin.read(data, 0, BUFFER)) != -1) { out.write(data, 0, count); } origin.close(); } }