Android Unzip File upZipFile(String zipFile, String folderPath)

Here you can find the source of upZipFile(String zipFile, String folderPath)

Description

up Zip File

Declaration

public static void upZipFile(String zipFile, String folderPath)
        throws ZipException, IOException 

Method Source Code

//package com.java2s;
import org.apache.http.protocol.HTTP;

import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;

public class Main {
    private static final int BUFF_SIZE = 1024 * 1024;

    public static void upZipFile(String zipFile, String folderPath)
            throws ZipException, IOException {
        File desDir = new File(folderPath);
        if (!desDir.exists()) {
            desDir.mkdirs();//from  ww w.  ja v  a 2 s  . c  o m
        }
        ZipFile zf = new ZipFile(zipFile);
        InputStream in = null;
        OutputStream out = null;
        try {
            for (Enumeration<?> entries = zf.entries(); entries
                    .hasMoreElements();) {
                ZipEntry entry = ((ZipEntry) entries.nextElement());
                in = zf.getInputStream(entry);
                String str = folderPath + File.separator + entry.getName();
                str = new String(str.getBytes("8859_1"), HTTP.UTF_8);
                File desFile = new File(str);
                if (!desFile.exists()) {
                    File fileParentDir = desFile.getParentFile();
                    if (!fileParentDir.exists()) {
                        fileParentDir.mkdirs();
                    }
                    desFile.createNewFile();
                }
                out = new FileOutputStream(desFile);
                byte buffer[] = new byte[BUFF_SIZE];
                int realLength;
                while ((realLength = in.read(buffer)) > 0) {
                    out.write(buffer, 0, realLength);
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (in != null)
                in.close();
            if (out != null)
                out.close();
            if (zf != null)
                zf.close();
        }
    }
}

Related

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