Java Zip Files addFileToZip(final File file, final String zipName, final ZipOutputStream zipout)

Here you can find the source of addFileToZip(final File file, final String zipName, final ZipOutputStream zipout)

Description

add File To Zip

License

Open Source License

Declaration

public static void addFileToZip(final File file, final String zipName, final ZipOutputStream zipout)
            throws IOException 

Method Source Code


//package com.java2s;
// Licensed under the MIT license. See License.txt in the repository root.

import java.io.BufferedInputStream;
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 {
    public static void addFileToZip(final File file, final String zipName, final ZipOutputStream zipout)
            throws IOException {
        InputStream in = null;/*from w  w  w  .  j av  a  2  s  .c  o  m*/
        try {
            in = new BufferedInputStream(new FileInputStream(file));
            final ZipEntry entry = new ZipEntry(zipName);
            zipout.putNextEntry(entry);
            final byte[] buffer = new byte[2048];
            int length;

            while ((length = in.read(buffer)) != -1) {
                zipout.write(buffer, 0, length);
            }
        } finally {
            if (in != null) {
                in.close();
            }
        }
    }
}

Related

  1. addFileToZip(File file, String entryName, ZipOutputStream zOut)
  2. addFileToZip(File file, String parentFolderName, ZipOutputStream zip)
  3. addFileToZip(File file, ZipOutputStream zos)
  4. addFileToZip(File in, File parent, ZipOutputStream out)
  5. addFileToZip(File root, File file, ZipOutputStream zos)
  6. addFileToZip(final String path, final String srcFile, final ZipOutputStream zip, boolean flag)
  7. addFileToZip(final String pathInsideZip, final File fileToZip, final ZipOutputStream outZip)
  8. addFileToZip(int skipprefix, File file, ZipOutputStream zipper)
  9. addFileToZip(String path, File srcFile, ZipOutputStream zip, boolean flag)