Android Unzip File upZipFile(File zipFile, String folderPath)

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

Description

up Zip File

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {

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

        File desDir = new File(folderPath);
        if (!desDir.exists()) {
            desDir.mkdirs();//  w  w  w  .ja  v  a  2  s  . c  om
        }

        ZipFile zf = new ZipFile(zipFile);
        for (Enumeration<?> entries = zf.entries(); entries
                .hasMoreElements();) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            InputStream in = zf.getInputStream(entry);

            if (entry.getName() == null
                    || entry.getName().trim().length() == 0) {
                continue;
            }
            String str = folderPath
                    + File.separator
                    + new String(entry.getName().getBytes("8859_1"),
                            "GB2312");

            File desFile = new File(str);
            if (!desFile.exists()) {
                File fileParentDir = desFile.getParentFile();
                if (!fileParentDir.exists()) {
                    fileParentDir.mkdirs();
                }
                desFile.createNewFile();
            } else {
                desFile.delete();
            }
            OutputStream out = new FileOutputStream(desFile);
            byte buffer[] = new byte[1024];
            int realLength;
            while ((realLength = in.read(buffer)) > 0) {
                out.write(buffer, 0, realLength);
            }
            in.close();
            out.close();

        }
        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. upZipFile(String zipFile, String folderPath)
  8. upZipSelectedFile(File zipFile, String folderPath, String nameContains)
  9. upZipSelectedFile(File zipFile, String folderPath, String nameContains)