Android Unzip File unpackZip(File zipFile, File location)

Here you can find the source of unpackZip(File zipFile, File location)

Description

unpack Zip

License

Open Source License

Declaration

public static void unpackZip(File zipFile, File location) 

Method Source Code

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

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;

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

public class Main {
    private static final int BUFFER = 8192;

    public static void unpackZip(File zipFile, File location) {
        try {/*  w w  w  .  ja  v  a  2 s . co m*/
            // Extract entries while creating required sub-directories
            ZipFile zf = new ZipFile(zipFile);
            Enumeration<?> e = zf.entries();

            while (e.hasMoreElements()) {
                ZipEntry entry = (ZipEntry) e.nextElement();
                File destinationFilePath = new File(location,
                        entry.getName());

                // create directories if required.
                destinationFilePath.getParentFile().mkdirs();

                // if the entry is directory, leave it. Otherwise extract it.
                if (!entry.isDirectory()) {
                    // Get the InputStream for current entry of the zip file
                    // using InputStream getInputStream(Entry entry) method.
                    BufferedInputStream bis = new BufferedInputStream(
                            zf.getInputStream(entry));

                    int b;
                    byte buffer[] = new byte[BUFFER];

                    // read the current entry from the zip file, extract it and
                    // write the extracted file.
                    FileOutputStream fos = new FileOutputStream(
                            destinationFilePath);
                    BufferedOutputStream bos = new BufferedOutputStream(
                            fos, BUFFER);

                    while ((b = bis.read(buffer, 0, 1024)) != -1) {
                        bos.write(buffer, 0, b);
                    }

                    bos.flush();
                    bos.close();
                    bis.close();
                }
            }

            zf.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    }
}

Related

  1. unzip(String zipFile, String location)
  2. unzip(String zipFile, String location)
  3. unpack(File zippedFile, File unpackedFile)
  4. unpack(File zippedFile, File unpackedFile)
  5. unpackZip(File zip, String unpackPath)
  6. unpackZip(String path, String zipname)
  7. unpackZip(String zipFile, String location)
  8. unzip(String[] namafileygdicrot, String zipFile, String location)
  9. unzip(String[] namafileygdicrot, String zipFile, String location)