集册 Java实例教程 Un Zip文件夹

Un Zip文件夹

欢马劈雪     最近更新时间:2020-01-02 10:19:05

677
Un Zip文件夹


import java.io.File;

import java.io.FileInputStream;
/* from 
n o w j a v a . c o m*/

import java.io.FileOutputStream;

import java.io.InputStream;

import java.util.ArrayList;

import java.util.List;

import java.util.zip.ZipEntry;

import java.util.zip.ZipFile;

import java.util.zip.ZipInputStream;

import java.util.zip.ZipOutputStream;


public class Main{
/** 
来 自 
时 代      J a v a   公   众 号 - nowjava.com
**/

    

    public static void UnZipFolder(String zipFileString,

            String outPathString) throws Exception {

        logger.d("UnZipFolder(String, String)");

        ZipInputStream inZip = new ZipInputStream(new FileInputStream(

                zipFileString));

        ZipEntry zipEntry;

        String szName = "";

        while ((zipEntry = inZip.getNextEntry()) != null) {

            szName = zipEntry.getName();

            if (zipEntry.isDirectory()) {

                szName = szName.substring(0, szName.length() - 1);

                File folder = new File(outPathString + File.separator

                        + szName);

                folder.mkdirs();

            } else {

                File file = new File(outPathString + File.separator

                        + szName);

                if (file.getParentFile() != null

                        && !file.getParentFile().exists()) {

                    file.getParentFile().mkdirs();

                }

                logger.e(outPathString + File.separator + szName);

                file.createNewFile();

                FileOutputStream out = new FileOutputStream(file);

        
展开阅读全文