Android Unzip File unzip(File zippedFile, File unpackedFile)

Here you can find the source of unzip(File zippedFile, File unpackedFile)

Description

unzip

Declaration

public static boolean unzip(File zippedFile, File unpackedFile) 

Method Source Code

//package com.java2s;
import android.util.Log;
import java.io.BufferedInputStream;
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;

public class Main {
    static final int BUFFER = 2048;

    public static boolean unzip(File zippedFile, File unpackedFile) {
        Log.d("ZipU", "staring unzip");
        try {//ww w .ja va 2s . co m
            BufferedOutputStream dest = null;
            FileInputStream fis = new FileInputStream(zippedFile);
            ZipInputStream zis = new ZipInputStream(
                    new BufferedInputStream(fis));
            ZipEntry entry;
            while ((entry = zis.getNextEntry()) != null) {
                System.out.println("-----------------------Extracting: "
                        + entry);
                int count;
                byte data[] = new byte[BUFFER];
                // write the files to the disk
                FileOutputStream fos = new FileOutputStream(unpackedFile);
                dest = new BufferedOutputStream(fos, BUFFER);
                while ((count = zis.read(data, 0, BUFFER)) != -1) {
                    dest.write(data, 0, count);
                }
                dest.flush();
                dest.close();
            }
            zis.close();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}

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 zipfile, File outputfolder)
  6. unzip(File zippedFile, File unpackedFile)
  7. unzip(File zippedFile, File unpackedFile)
  8. unzip(String zipFile, String location)
  9. unzip(String zipFile, String location)