Here you can find the source of zipFile(File file)
private static void zipFile(File file)
//package com.java2s; /*//w ww .j av a2s . co m * Copyright 2005 The Regents of the University of Michigan * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.io.File; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { private static ZipOutputStream zos = null; private static String source = "", target = ""; private static void zipFile(File file) { if (file.isDirectory()) { if (file.getName().equalsIgnoreCase(".metadata") || file.getName().equalsIgnoreCase("Libraries") || file.getName().equalsIgnoreCase("RepositoryBuild") || file.getName().equalsIgnoreCase("images")) { return; } File list[] = file.listFiles(); for (int i = 0; i < list.length; i++) { zipFile(list[i]); } } else { try { String strAbsPath = file.getPath(); String strZipEntryName = strAbsPath.substring(source.length() + 1, strAbsPath.length()); byte[] b = new byte[(int) (file.length())]; ZipEntry cpZipEntry = new ZipEntry(strZipEntryName); zos.putNextEntry(cpZipEntry); zos.write(b, 0, (int) file.length()); zos.closeEntry(); } catch (Exception e) { e.printStackTrace(); } } } }