Java Zip File List zipFiles(String files[], String fielPath)

Here you can find the source of zipFiles(String files[], String fielPath)

Description

zip Files

License

Open Source License

Declaration

public static byte[] zipFiles(String files[], String fielPath) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedInputStream;

import java.io.ByteArrayOutputStream;

import java.io.FileInputStream;

import java.io.IOException;

import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
    public static byte[] zipFiles(String files[], String fielPath) throws IOException {

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ZipOutputStream zos = new ZipOutputStream(bout);
        zos.setLevel(6);/*from www .  j a  va 2s  .  co m*/
        byte[] bytes = new byte[10000];

        for (int i = 0; i < files.length; i++) {

            FileInputStream fis = new FileInputStream(fielPath + "\\" + files[i]);
            BufferedInputStream bis = new BufferedInputStream(fis);

            zos.putNextEntry(new ZipEntry(files[i]));
            int bytesCount = -1;
            while ((bytesCount = bis.read(bytes)) != -1) {
                zos.write(bytes, 0, bytesCount);
            }
            zos.closeEntry();
            bis.close();
            fis.close();
        }
        zos.flush();
        bout.flush();

        zos.close();
        bout.close();
        return bout.toByteArray();

    }
}

Related

  1. zipFiles(List files, File output)
  2. zipFiles(List files, OutputStream os)
  3. zipFiles(List srcfile, File zipfile)
  4. ZipFiles(String destination, Vector files)
  5. zipFiles(String filename, String[] files)
  6. zipFiles(String filesPathToZip, String pathToSave)
  7. zipFiles(String output, String sDir, String sSearch)
  8. zipFiles(String output_dir, List files)
  9. zipFiles(String source, String target)