Android Unzip File upZipSelectedFile(File zipFile, String folderPath, String nameContains)

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

Description

up Zip Selected File

Declaration

public static ArrayList<File> upZipSelectedFile(File zipFile,
            String folderPath, String nameContains) throws ZipException,
            IOException 

Method Source Code

//package com.java2s;
import java.io.*;
import java.util.ArrayList;

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

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

    public static ArrayList<File> upZipSelectedFile(File zipFile,
            String folderPath, String nameContains) throws ZipException,
            IOException {//from www .j  a v a  2  s. c  o m

        ArrayList<File> fileList = new ArrayList<File>();

        File desDir = new File(folderPath);
        if (!desDir.exists()) {
            desDir.exists();
        }

        ZipFile zf = new ZipFile(zipFile);
        for (Enumeration<?> entries = zf.entries(); entries
                .hasMoreElements();) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            if (entry.getName().contains(nameContains)) {
                InputStream in = zf.getInputStream(entry);
                String str = folderPath + File.separator + entry.getName();
                str = new String(str.getBytes("8859_1"), "GB2312");
                File desFile = new File(str);
                if (!desFile.exists()) {
                    File fileParentDir = desFile.getParentFile();
                    if (!fileParentDir.exists()) {
                        fileParentDir.mkdirs();
                    }
                    desFile.createNewFile();
                }

                OutputStream out = new FileOutputStream(desFile);
                byte buffer[] = new byte[BUFF_SIZE];
                int realLength;
                while ((realLength = in.read(buffer)) > 0) {
                    out.write(buffer, 0, realLength);
                }

                in.close();
                out.close();
                fileList.add(desFile);
            }
        }

        return fileList;
    }
}

Related

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