Android Unzip File unpackZip(String path, String zipname)

Here you can find the source of unpackZip(String path, String zipname)

Description

unpack Zip

Declaration

public static boolean unpackZip(String path, String zipname) 

Method Source Code

//package com.java2s;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    public static boolean unpackZip(String path, String zipname) {
        InputStream inputStream;//  w  w w .  j a va2s.  com
        ZipInputStream zipInputStream;

        try {
            int count;
            String filename;
            ZipEntry zipEntry;
            byte[] buffer = new byte[1024];

            inputStream = new FileInputStream(path + zipname);
            zipInputStream = new ZipInputStream(new BufferedInputStream(
                    inputStream));

            while ((zipEntry = zipInputStream.getNextEntry()) != null) {
                filename = zipEntry.getName();

                if (zipEntry.isDirectory()) {
                    File f = new File(path + filename);
                    f.mkdirs();
                    continue;
                }

                FileOutputStream fileOutputStream = new FileOutputStream(
                        path + filename);

                while ((count = zipInputStream.read(buffer)) != -1) {
                    fileOutputStream.write(buffer, 0, count);
                }

                fileOutputStream.close();
                zipInputStream.closeEntry();
            }

            zipInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }

        return true;
    }
}

Related

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