集册 Java实例教程 将文件添加到当前的zip输出流

将文件添加到当前的zip输出流

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

443
将文件添加到当前的zip输出流
/**from NowJava.com - 时  代  Java**/


//package com.nowjava;

import java.io.BufferedInputStream;


import java.io.File;

import java.io.FileInputStream;

import java.io.FileNotFoundException;


import java.io.IOException;


import java.util.zip.ZipEntry;


import java.util.zip.ZipOutputStream;


public class Main {

    /**

     * Size of the buffer to read/write data

     */

    private static final int BUFFER_SIZE = 4096;
    /** 
     来自 n o w j a v a . c o m - 时代Java**/


    /**

     * Adds a file to the current zip output stream

     * 

     * @param file

     *            the file to be added

     * @param zos

     *            the current zip output stream

     * @throws FileNotFoundException

     * @throws IOException

     */

    private static void zipFile(File file, ZipOutputStream zos)

            throws FileNotFoundException, IOException {

        zos.putNextEntry(new ZipEntry(file.getName()));

        BufferedInputStream bis = null;

        try {

            bis = new BufferedInputStream(new FileInputStream(file));

            long bytesRead = 0;

            byte[] bytesIn = new byte[BUFFER_SIZE];
展开阅读全文