Here you can find the source of zipFiles(File[] dirList, ZipOutputStream zos)
Parameter | Description |
---|---|
dirList | a parameter |
zos | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void zipFiles(File[] dirList, ZipOutputStream zos) throws IOException
//package com.java2s; /******************************************************************************* * * * Copyright (C) 2007, 2010 - The University of Liverpool * * This program is free software; you can redistribute it and/or modify it under the terms * * of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, * * or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. * *// w w w .j a va 2 s.c om * * Author: Fabio Corubolo * * Email: corubolo@gmail.com * *******************************************************************************/ 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 { /** * Utility to zip a set of files to a ZipOutputStream * @param dirList * @param zos * @throws IOException */ public static void zipFiles(File[] dirList, ZipOutputStream zos) throws IOException { byte[] readBuffer = new byte[2156]; int bytesIn = 0; for (File f : dirList) { if (f.isDirectory()) continue; FileInputStream fis = new FileInputStream(f); ZipEntry anEntry = new ZipEntry(f.getName()); zos.putNextEntry(anEntry); while ((bytesIn = fis.read(readBuffer)) != -1) zos.write(readBuffer, 0, bytesIn); fis.close(); } } }