Java Zip Files addFileToZip(ZipOutputStream zipOutputStream, String path, byte[] bytes)

Here you can find the source of addFileToZip(ZipOutputStream zipOutputStream, String path, byte[] bytes)

Description

Adds a file to a .zip file

License

Apache License

Parameter

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

Exception

Parameter Description
IOException an exception

Declaration

public static void addFileToZip(ZipOutputStream zipOutputStream, String path, byte[] bytes) throws IOException 

Method Source Code


//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();
    }
}

Related

  1. addFileToZip(String path, File srcFile, ZipOutputStream zip, String destZipFile)
  2. addFileToZip(String path, String srcFile, ZipOutputStream zip)
  3. addFileToZip(String path, String srcFile, ZipOutputStream zip)
  4. addFileToZip(ZipOutputStream out, InputStream in, String entry)
  5. addFileToZip(ZipOutputStream zipOutputStream, File file, String basePath)
  6. addFileToZip(ZipOutputStream zos, File file, File rootDir)
  7. addFileToZipOutputStream(File file, ZipOutputStream zipOs)
  8. addToZip(byte[] zip, String file, String fileName)
  9. addToZip(File directoryToZip, File file, ZipOutputStream zos)