Android Unzip File unzip(final String zipFile, String outPath)

Here you can find the source of unzip(final String zipFile, String outPath)

Description

unzip

Declaration

public static void unzip(final String zipFile, String outPath) 

Method Source Code

//package com.java2s;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import android.util.Log;

public class Main {
    public static void unzip(final String zipFile, String outPath) {
        if (!outPath.endsWith(File.separator)) {
            outPath = outPath + File.separator;
        }//www  . ja  v a  2s . co m
        try {
            final FileInputStream fin = new FileInputStream(zipFile);
            final ZipInputStream zis = new ZipInputStream(fin);
            ZipEntry entry = null;

            while ((entry = zis.getNextEntry()) != null) {
                Log.v("Decompress", "Unzipping " + entry.getName());
                if (entry.isDirectory()) {
                    final File f = new File(outPath, entry.getName());
                    if (!f.exists()) {
                        f.mkdirs();
                    }
                } else {
                    int size;
                    final byte[] buffer = new byte[2048];

                    final File f = new File(outPath, entry.getName());
                    final FileOutputStream fos = new FileOutputStream(f);
                    final BufferedOutputStream bos = new BufferedOutputStream(
                            fos, buffer.length);

                    while ((size = zis.read(buffer, 0, buffer.length)) != -1) {
                        bos.write(buffer, 0, size);
                    }
                    bos.flush();
                    bos.close();
                }
            }

            zis.close();
            fin.close();
        } catch (final Exception e) {
            Log.e("Decompress", "unzip", e);
        }

    }
}

Related

  1. unpackZip(File zipFile, File location)
  2. unpackZip(String path, String zipname)
  3. unpackZip(String zipFile, String location)
  4. unzip(String[] namafileygdicrot, String zipFile, String location)
  5. unzip(String[] namafileygdicrot, String zipFile, String location)
  6. upZip(String zipFilePath, String fileString)
  7. upZip(String zipFilePath, String fileString)
  8. upZipFile(File zipFile, String folderPath)
  9. upZipFile(File zipFile, String folderPath)