Skip to content

Instantly share code, notes, and snippets.

@shankaraman
Created December 22, 2015 23:57
Show Gist options
  • Save shankaraman/7079bd55e9b1f17cbc49 to your computer and use it in GitHub Desktop.
Save shankaraman/7079bd55e9b1f17cbc49 to your computer and use it in GitHub Desktop.
[ZIP] Minor Project
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