Here you can find the source of zip(File directory, File base, ZipOutputStream zos)
Parameter | Description |
---|---|
directory | a parameter |
base | a parameter |
zos | a parameter |
private static void zip(File directory, File base, ZipOutputStream zos) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { /**/*w ww .j a va 2s .c om*/ * @author comsince * @param directory * @param base * @param zos * * */ private static 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 FileInputStream(files[i]); ZipEntry entry = new ZipEntry(files[i].getPath().substring( base.getPath().length() + 1)); zos.putNextEntry(entry); while (-1 != (read = in.read(buffer))) { zos.write(buffer, 0, read); } in.close(); } } } }