Skip to content

Instantly share code, notes, and snippets.

@frankcash
Created May 8, 2014 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frankcash/48e33662bf16d777035c to your computer and use it in GitHub Desktop.
Save frankcash/48e33662bf16d777035c to your computer and use it in GitHub Desktop.
Zippy Zoop
public class ZippyZoop {
public static void zippyZoop(String fileName, String zipName){
try{
byte[] buffer = new byte[1024];
FileOutputStream fos = new FileOutputStream(zipName);
ZipOutputStream zos = new ZipOutputStream(fos);
File srcFile = new File(fileName);
FileInputStream fis = new FileInputStream(srcFile);
//something
zos.putNextEntry(new ZipEntry(srcFile.getName()));
int length;
while((length = fis.read(buffer))>0){
zos.write(buffer, 0, length);
}
zos.closeEntry();
fis.close();
zos.close();
}catch(IOException ioe){
//something something something
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
zippyZoop("C:\\Users\\fcash\\Documents\\test\\foo.txt", "C:\\Users\\fcash\\Documents\\test\\aphrodite.zip");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment