Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

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 {
    private static final int BUFFERED_SIZE = 1024;

    public static void zipMutiCompress(File[] srcfile, File destFile) {
        byte[] buf = new byte[BUFFERED_SIZE];
        try {
            ZipOutputStream out = new ZipOutputStream(new FileOutputStream(destFile));
            if (null != srcfile && srcfile.length > 0) {
                for (int i = 0; i < srcfile.length; i++) {
                    File file = srcfile[i];
                    if (null != file) {
                        FileInputStream in = new FileInputStream(file);
                        out.putNextEntry(new ZipEntry(file.getName()));
                        int len;
                        while ((len = in.read(buf)) > 0) {
                            out.write(buf, 0, len);
                        }
                        out.closeEntry();
                        in.close();
                    }
                }
            }
            out.close();
        } catch (IOException e) {

        }
    }
}