Android Unzip File unZip(File srcFile, File targetFile)

Here you can find the source of unZip(File srcFile, File targetFile)

Description

un Zip

Declaration

@SuppressWarnings("resource")
public static void unZip(File srcFile, File targetFile) 

Method Source Code

//package com.java2s;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import java.util.zip.ZipInputStream;

public class Main {

    @SuppressWarnings("resource")
    public static void unZip(File srcFile, File targetFile) {
        if (!srcFile.exists())
            return;
        if (!targetFile.getParentFile().exists())
            targetFile.getParentFile().mkdir();
        while (true) {
            FileOutputStream localFileOutputStream;
            byte[] arrayOfByte;
            int i;
            try {
                FileInputStream localFileInputStream = new FileInputStream(
                        srcFile);/* w ww  .  j  a va2 s.  c om*/
                localFileOutputStream = new FileOutputStream(targetFile);
                ZipInputStream localZipInputStream = new ZipInputStream(
                        localFileInputStream);
                arrayOfByte = new byte[1024];
                i = localZipInputStream.read(arrayOfByte);
                if (i <= 0) {
                    localFileInputStream.close();
                    localFileOutputStream.close();
                    return;
                }
            } catch (Exception localException) {
                localException.printStackTrace();
                return;
            }
            try {
                localFileOutputStream.write(arrayOfByte, 0, i);
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

Related

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