Created
December 22, 2015 23:57
-
-
Save shankaraman/7079bd55e9b1f17cbc49 to your computer and use it in GitHub Desktop.
[ZIP] Minor Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.zip.*; | |
public class compress | |
{ | |
public static void main(String [] args) | |
{ | |
byte[] buffer = new byte[1024]; | |
try{ | |
FileOutputStream fos = new FileOutputStream("mellon.zip"); | |
ZipOutputStream zos = new ZipOutputStream(fos); | |
ZipEntry ze= new ZipEntry("./mellon.txt"); | |
zos.putNextEntry(ze); | |
FileInputStream in = new FileInputStream("./mellon.txt"); | |
int len; | |
while ((len = in.read(buffer)) > 0) | |
{ | |
zos.write(buffer, 0, len); | |
} | |
in.close(); | |
zos.closeEntry(); | |
//remember close it | |
zos.close(); | |
System.out.println("Done"); | |
} | |
catch(IOException ex) | |
{ | |
ex.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment