Java Zip File zipFile(File inputFile, File outputZip)

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

Description

zip File

License

Open Source License

Declaration

public static void zipFile(File inputFile, File outputZip) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.*;

import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
    public static void zipFile(File inputFile, File outputZip) {
        byte[] buffer = new byte[1024];

        try {/*from  www.j a va2  s  .  c om*/
            FileOutputStream fos = new FileOutputStream(outputZip);
            ZipOutputStream zos = new ZipOutputStream(fos);
            ZipEntry ze = new ZipEntry(inputFile.getName());
            zos.putNextEntry(ze);
            FileInputStream in = new FileInputStream(inputFile);

            int len;
            while ((len = in.read(buffer)) > 0) {
                zos.write(buffer, 0, len);
            }

            in.close();
            zos.closeEntry();

            zos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Related

  1. zipFile(File file, File output)
  2. zipFile(File file, File zipFile)
  3. zipFile(File file, String zipFile)
  4. zipFile(File fileToZip, String fileName, ZipOutputStream zipOut)
  5. zipFile(File input, File output)
  6. zipFile(File inputFile, String zipFilePath)
  7. zipFile(File resFile, ZipOutputStream zipout, String rootpath)
  8. zipFile(File root, String outFileFullName, String[] suffixs, String[] nameMatche, String[] nameNotMatche)
  9. zipFile(File source, File dest)