Android Unzip File unzip(File zip, File extractTo)

Here you can find the source of unzip(File zip, File extractTo)

Description

unzip

Declaration

public static final void unzip(File zip, File extractTo)
            throws IOException 

Method Source Code

//package com.java2s;
import java.io.BufferedOutputStream;
import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    public static final void unzip(File zip, File extractTo)
            throws IOException {
        ZipFile archive = new ZipFile(zip);
        @SuppressWarnings("rawtypes")
        Enumeration e = archive.entries();
        while (e.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) e.nextElement();
            File file = new File(extractTo, entry.getName());
            if (entry.isDirectory() && !file.exists()) {
                file.mkdirs();//from ww w.  ja  v a 2  s . c  o  m
            } else {
                if (!file.getParentFile().exists()) {
                    file.getParentFile().mkdirs();
                }

                InputStream in = archive.getInputStream(entry);
                BufferedOutputStream out = new BufferedOutputStream(
                        new FileOutputStream(file));

                byte[] buffer = new byte[8192];
                int read;

                while (-1 != (read = in.read(buffer))) {
                    out.write(buffer, 0, read);
                }

                in.close();
                out.close();
            }
        }
    }
}

Related

  1. unzip(File archive, File path)
  2. unzip(File target, File dest)
  3. unzip(File target, File dest)
  4. unzip(File zipfile, File outputfolder)
  5. unzip(File zippedFile, File unpackedFile)
  6. unzip(File zippedFile, File unpackedFile)
  7. unzip(File zippedFile, File unpackedFile)