集册 Java实例教程 邮编目录

邮编目录

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

439
邮编目录
//n  o  w  j  a  v  a . c o m 提 供


//package com.nowjava;


import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;


import java.util.zip.ZipEntry;


import java.util.zip.ZipOutputStream;


public class Main {

    public static final void zipDirectory(File directory, File zip)

            throws IOException {

        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zip));

        zos.setLevel(9);
        /*
        时 代      J a v a   公   众 号 - nowjava.com
        */

        zip(directory, directory, zos);

        zos.close();

    }


    /**

     * 

     * 

     * @param directory

     * @param zip  full path to zip archive with it name

     * @throws java.io.IOException

     */

    public static final void zipDirectory(String directory, String zip)

            throws IOException {

        zipDirectory(new File(directory), new File(zip));

    }


    private static final void zip(File directory, File base,

            ZipOutputStream zos) throws IOException {

        File[] files = directory.listFiles();

        byte[] buffer = new byte[8192];

        int read = 0;

        for (int i = 0, n = files.length; i < n; i++) {

            if (files[i].isDirectory()) {

                zip(files[i], base, zos);

            } else {

                FileInputStream in = new 
展开阅读全文