Java examples for File Path IO:Zip File
zip File
//package com.java2s; 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 w w w. j a va 2s . 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(); } } }