Android Zip Unzip File zip(String[] files, String zipFile)

Here you can find the source of zip(String[] files, String zipFile)

Description

zip

Declaration

public static void zip(String[] files, String zipFile) 

Method Source Code

//package com.java2s;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
    private static int BUFFER_SIZE = 1024;

    public static void zip(String[] files, String zipFile) {
        BufferedInputStream origin = null;
        try {// ww w  .  j  a v  a  2 s .  c om
            ZipOutputStream out = new ZipOutputStream(
                    new BufferedOutputStream(new FileOutputStream(zipFile)));
            byte data[] = new byte[BUFFER_SIZE];
            for (int i = 0; i < files.length; i++) {
                FileInputStream fi = new FileInputStream(files[i]);
                origin = new BufferedInputStream(fi, BUFFER_SIZE);
                try {
                    ZipEntry entry = new ZipEntry(
                            files[i].substring(files[i].lastIndexOf("/") + 1));
                    out.putNextEntry(entry);
                    int count;
                    while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
                        out.write(data, 0, count);
                    }
                } finally {
                    origin.close();
                }
            }
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. zip(String sourceDir, String zipFile)
  2. zip(String[] files, String destZipFilePath)
  3. zip(String[] files, String zipFile)
  4. zip(String[] files, String zipFile)
  5. zip(String[] files, String zipFile)
  6. zip(String[] files, String zipFile)
  7. zip(File srcFile, File targetFile)
  8. zip(File[] _files, File _zipFile)
  9. zip(List listFiles, String destZipFilePath)