Create a Compressed Zip File in Java

(813 Views)


This is a simple Java code to Create a zip File ......

Write a program to compress files in zip using Java

Main.java

import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { public static void main(String[] args) throws Exception { FileInputStream in = new FileInputStream("list.txt"); ZipOutputStream out = new ZipOutputStream(new FileOutputStream("compressed.zip")); out.putNextEntry(new ZipEntry("list.txt")); byte[] buffer = new byte[1024]; int bytesRead; while ((bytesRead = in.read(buffer)) > 0) { out.write(buffer, 0, bytesRead); } out.closeEntry(); out.close(); in.close(); } }

Solution Worked 0 UpvotesUpvote

        

Solution Didn't Worked 0 DownvotesDownvote



Comments



Get Programming Help
Search

Play 2048 Game Online


Search Tags