Here you can find the source of addFileToZip(ZipOutputStream out, InputStream in, String entry)
Parameter | Description |
---|---|
out | the zip file |
in | the input stream to add into the zip |
entry | the entry for the file to add into the zip (not null) |
private static void addFileToZip(ZipOutputStream out, InputStream in, String entry)
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.io.InputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { /**// w w w . j a v a2s .co m * Adds a file into a zip archive. * * @param out the zip file * @param in the input stream to add into the zip * @param entry the entry for the file to add into the zip (not null) */ private static void addFileToZip(ZipOutputStream out, InputStream in, String entry) { byte[] buf = new byte[1024]; // Create a buffer for reading the files ZipEntry ze = new ZipEntry(entry); try { out.putNextEntry(ze); int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.closeEntry(); } catch (Exception e) { e.printStackTrace(); } } }