Java Zip File List zipFiles(File[] dirList, ZipOutputStream zos)

Here you can find the source of zipFiles(File[] dirList, ZipOutputStream zos)

Description

Utility to zip a set of files to a ZipOutputStream

License

Open Source License

Parameter

Parameter Description
dirList a parameter
zos a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void zipFiles(File[] dirList, ZipOutputStream zos)
        throws IOException 

Method Source Code

//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();
        }
    }
}

Related

  1. zipFiles(ArrayList files, String destZipFile)
  2. zipFiles(Collection resFileList, File zipFile)
  3. zipFiles(File file, JarOutputStream jos, String pathName)
  4. zipFiles(File output, File root, List fileList)
  5. zipFiles(File rootDir, File currDir, ZipOutputStream zos)
  6. zipFiles(File[] listFiles2Zip, File output)
  7. zipFiles(final File outputFile, final File[] files)
  8. zipFiles(List files, File output)
  9. zipFiles(List files, OutputStream os)