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

Apache License

Declaration

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

Method Source Code

//package com.java2s;
/*/*from w  w  w .ja v a 2s.  c  o m*/
 * Copyright (c) 2014,KJFrameForAndroid Open Source Project,??.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

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(File zipFile, String folderPath)
            throws ZipException, IOException {
        File desDir = new File(folderPath);
        if (!desDir.exists()) {
            desDir.mkdirs();
        }
        ZipFile zf = new ZipFile(zipFile);
        for (Enumeration<?> entries = zf.entries(); entries
                .hasMoreElements();) {
            ZipEntry entry = ((ZipEntry) entries.nextElement());
            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();
        }
    }
}

Related

  1. unzip(String[] namafileygdicrot, String zipFile, String location)
  2. unzip(final String zipFile, String outPath)
  3. upZip(String zipFilePath, String fileString)
  4. upZip(String zipFilePath, String fileString)
  5. upZipFile(File zipFile, String folderPath)
  6. upZipFile(File zipFile, String folderPath)
  7. upZipFile(File zipFile, String folderPath)
  8. upZipFile(File zipFile, String folderPath)
  9. upZipFile(File zipFile, String folderPath)