Android Unzip File unZip(String zipFile, String targetPath)

Here you can find the source of unZip(String zipFile, String targetPath)

Description

un Zip

Declaration

public static boolean unZip(String zipFile, String targetPath) 

Method Source Code

//package com.java2s;

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 {
    public static boolean unZip(String zipFile, String targetPath) {

        //create target location folder if not exist
        createDir(targetPath, "");

        try {//from   ww  w.j av  a 2  s.  c o m
            FileInputStream fin = new FileInputStream(zipFile);
            ZipInputStream zin = new ZipInputStream(fin);
            ZipEntry ze = null;
            while ((ze = zin.getNextEntry()) != null) {

                //create dir if required while unzipping
                if (ze.isDirectory()) {
                    createDir(targetPath, ze.getName());
                } else {
                    FileOutputStream fout = new FileOutputStream(targetPath
                            + ze.getName());
                    for (int c = zin.read(); c != -1; c = zin.read()) {
                        fout.write(c);
                    }

                    zin.closeEntry();
                    fout.close();
                }

            }
            zin.close();
            return true;
        } catch (Exception e) {
            System.out.println(e);
        }
        return false;
    }

    private static void createDir(String path, String folder) {
        File f = new File(path + folder);
        if (!f.isDirectory()) {
            f.mkdirs();
        }
    }
}

Related

  1. upZipFile(String zipFile, String folderPath)
  2. upZipFile(String zipFile, String folderPath)
  3. upZipSelectedFile(File zipFile, String folderPath, String nameContains)
  4. upZipSelectedFile(File zipFile, String folderPath, String nameContains)
  5. unZip(File srcFile, File targetFile)
  6. unZip(String zipfile, String destDir)
  7. UpZip(String zipFileString, String fileString)
  8. UpZip(String zipFileString, String fileString)
  9. UpZip(String zipFileString, String fileString)