Android Unzip Folder UnZipFolder(String zipFileString, String outPathString)

Here you can find the source of UnZipFolder(String zipFileString, String outPathString)

Description

Un Zip Folder

Declaration

public static void UnZipFolder(String zipFileString,
        String outPathString) throws Exception 

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 void UnZipFolder(String zipFileString,
            String outPathString) throws Exception {
        ZipInputStream inZip = new ZipInputStream(new FileInputStream(
                zipFileString));//from   ww  w. j a  va 2s. com
        ZipEntry zipEntry;
        String szName = "";

        while ((zipEntry = inZip.getNextEntry()) != null) {
            szName = zipEntry.getName();

            if (zipEntry.isDirectory()) {

                // get the folder name of the widget
                szName = szName.substring(0, szName.length() - 1);
                File folder = new File(outPathString + File.separator
                        + szName);
                folder.mkdirs();

            } else {

                File file = new File(outPathString + File.separator
                        + szName);
                File parent = file.getParentFile();
                if (!parent.exists()) {
                    parent.mkdirs();
                }
                file.createNewFile();
                // get the output stream of the file
                FileOutputStream out = new FileOutputStream(file);
                int len;
                byte[] buffer = new byte[1024];
                // read (len) bytes into buffer
                while ((len = inZip.read(buffer)) != -1) {
                    // write (len) byte from buffer at the position 0
                    out.write(buffer, 0, len);
                    out.flush();
                }
                out.close();
            }
        }// end of while

        inZip.close();

    }
}

Related

  1. unZipFolder(InputStream input, String outPathString)
  2. unZipFolder(String s, String s1)
  3. unZipFolder(String zipFileString, String outPathString)
  4. unZipFolder(String zipFileString, String outPathString)
  5. UnZipFolder(String zipFileString, String outPathString)
  6. UnZipFolder(String zipFileString, String outPathString)
  7. UnzipSubDir(InputStream is, String subdir, String targetPath)
  8. UnzipSubDir(String source, String subdir, String targetPath)
  9. unZipFolder(InputStream zipFileStream, String outPathString)