Android Unzip File unzip(File zipfile, File outputfolder)

Here you can find the source of unzip(File zipfile, File outputfolder)

Description

unzip

Declaration

public static void unzip(File zipfile, File outputfolder)
            throws Exception 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    static byte[] buffer = new byte[4096];

    public static void unzip(File zipfile, File outputfolder)
            throws Exception {
        ZipFile zip = new ZipFile(zipfile);

        Enumeration entries = zip.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) entries.nextElement();
            File unzipped = new File(outputfolder, entry.getName());

            if (entry.isDirectory() && !unzipped.exists()) {
                unzipped.mkdirs();//from w w  w  .jav  a  2 s . c  om
                continue;
            } else if (!unzipped.getParentFile().exists()) {
                unzipped.getParentFile().mkdirs();
            }

            InputStream in = zip.getInputStream(entry);
            FileOutputStream fos = new FileOutputStream(unzipped);

            int count;
            while ((count = in.read(buffer, 0, buffer.length)) != -1) {
                fos.write(buffer, 0, count);
            }

            fos.close();
            in.close();
        }
    }
}

Related

  1. unzip(File archive, File path)
  2. unzip(File target, File dest)
  3. unzip(File target, File dest)
  4. unzip(File zip, File extractTo)
  5. unzip(File zippedFile, File unpackedFile)
  6. unzip(File zippedFile, File unpackedFile)
  7. unzip(File zippedFile, File unpackedFile)
  8. unzip(String zipFile, String location)