Here you can find the source of addFileToZip(File file, String entryName, ZipOutputStream zos)
Parameter | Description |
---|---|
file | a parameter |
entryName | a parameter |
zos | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static final void addFileToZip(File file, String entryName, ZipOutputStream zos) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { /**// ww w.j a v a 2s. c om * Inserts a file into a zipstream using the specified entryName. * * @param file * @param entryName * @param zos * @throws IOException */ public static final void addFileToZip(File file, String entryName, ZipOutputStream zos) throws IOException { byte[] buffer = new byte[8192]; int read = 0; FileInputStream in = new FileInputStream(file); ZipEntry entry = new ZipEntry(entryName); zos.putNextEntry(entry); while (-1 != (read = in.read(buffer))) { zos.write(buffer, 0, read); } in.close(); } /** * Inserts a stream into a zipstream using the specified entryName. * * @param in * @param entryName * @param zos * @throws IOException */ public static final void addFileToZip(InputStream in, String entryName, ZipOutputStream zos) throws IOException { byte[] buffer = new byte[8192]; int read = 0; ZipEntry entry = new ZipEntry(entryName); zos.putNextEntry(entry); while (-1 != (read = in.read(buffer))) { zos.write(buffer, 0, read); } in.close(); } }