Here you can find the source of addFileToZip(ZipOutputStream zipOutputStream, String path, byte[] bytes)
Parameter | Description |
---|---|
zipOutputStream | instance of ZipOutputStream |
path | Path to where you want to place the file inside the .zip |
bytes | The bytes of the file you want to add to the .zip |
Parameter | Description |
---|---|
IOException | an exception |
public static void addFileToZip(ZipOutputStream zipOutputStream, String path, byte[] bytes) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { /**//from w w w. ja v a 2s. c o m * Adds a file to a .zip file * * @param zipOutputStream instance of ZipOutputStream * @param path Path to where you want to place the file inside the .zip * @param bytes The bytes of the file you want to add to the .zip * @throws IOException */ public static void addFileToZip(ZipOutputStream zipOutputStream, String path, byte[] bytes) throws IOException { zipOutputStream.putNextEntry(new ZipEntry(path)); zipOutputStream.write(bytes, 0, bytes.length); zipOutputStream.closeEntry(); } }