Java Zip File zipFile(File file, File zipFile)

Here you can find the source of zipFile(File file, File zipFile)

Description

zip File

License

Apache License

Declaration

public static void zipFile(File file, File zipFile) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.util.zip.ZipEntry;

import java.util.zip.ZipOutputStream;

public class Main {
    public static void zipFile(File file, File zipFile) throws Exception {
        byte[] buffer = new byte[8192];
        int read = 0;

        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile));

        FileInputStream fis = new FileInputStream(file);

        zos.putNextEntry(new ZipEntry(file.getName()));

        while ((read = fis.read(buffer)) > 0) {
            zos.write(buffer, 0, read);//from w  ww  .  jav a 2  s . co m
        }

        fis.close();
        zos.closeEntry();
        zos.close();
    }
}

Related

  1. zip(String zipName, String[] fileNames, boolean path)
  2. zip(String zipPath, Map input)
  3. zipFile(File aFileToZip)
  4. zipFile(File file)
  5. zipFile(File file, File output)
  6. zipFile(File file, String zipFile)
  7. zipFile(File fileToZip, String fileName, ZipOutputStream zipOut)
  8. zipFile(File input, File output)
  9. zipFile(File inputFile, File outputZip)