集册 Java实例教程 将ZipFile中的条目提取到dest中

将ZipFile中的条目提取到dest中

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

492
将ZipFile中的条目提取到dest中
/* 
*来 自
 N o w  J a v a  . c o m
*/


//package com.nowjava;

import java.io.BufferedInputStream;

import java.io.BufferedOutputStream;

import java.io.File;


import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;


import java.util.zip.ZipEntry;

import java.util.zip.ZipFile;


public class Main {

    /**

     * Extracts entry from zf into dest

     * @param zf the zip file to extract from

     * @param entry the entry in the zip to extract

     * @param dest the destination to extract to

     *///时代Java公众号 - nowjava.com 提 供

    public static void ExtractFromZip(ZipFile zf, ZipEntry entry, File dest)

            throws IOException {

        if (entry.isDirectory()) {

            dest.mkdirs();

            return;

        }


        //if (!dest.getParentFile().exists())

        dest.getParentFile().mkdirs();


        if (!dest.exists())

            dest.createNewFile();


        int bufSize = 1024;


        InputStream is = zf.getInputStream(entry);

        BufferedInputStream in = new BufferedInputStream(is, bufSize);


        FileOutputStream fos = new FileOutputStream(dest);

        BufferedOutputStream out = new BufferedOutputStream(fos, bufSize);


        
展开阅读全文