Java Zip File List zipFiles(List srcfile, File zipfile)

Here you can find the source of zipFiles(List srcfile, File zipfile)

Description

zip Files

License

Apache License

Declaration

public static void zipFiles(List<File> srcfile, File zipfile) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.util.List;
import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

public class Main {

    public static void zipFiles(List<File> srcfile, File zipfile) {
        byte[] buf = new byte[4096];
        try {/*from   w ww  .  jav  a  2s .c  om*/
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
            for (File file : srcfile) {
                FileInputStream in = new FileInputStream(file);
                out.putNextEntry(new ZipEntry(file.getName()));
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
                out.closeEntry();
                in.close();
            }
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. zipFiles(File[] dirList, ZipOutputStream zos)
  2. zipFiles(File[] listFiles2Zip, File output)
  3. zipFiles(final File outputFile, final File[] files)
  4. zipFiles(List files, File output)
  5. zipFiles(List files, OutputStream os)
  6. ZipFiles(String destination, Vector files)
  7. zipFiles(String filename, String[] files)
  8. zipFiles(String files[], String fielPath)
  9. zipFiles(String filesPathToZip, String pathToSave)