Compressing a File This example creates a ZIP file with one entry. try { String inFilename = "infile"; String outFilename = "outfile.zip"; FileInputStream in = new FileInputStream( inFilename); ZipOutputStream out = new ZipOutputStream( new FileOutputStream(outFilename)); // Add ZIP entry to output stream. out.putNextEntry(new ZipEntry(inFilename)); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } out.closeEntry(); out.close(); in.close(); } catch (IOException e) { }