Created
January 9, 2012 11:57
-
-
Save yanaga/1582650 to your computer and use it in GitHub Desktop.
Simple ZipOutputStream Example
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.FileInputStream; | |
import java.io.FileOutputStream; | |
import java.util.zip.ZipEntry; | |
import java.util.zip.ZipOutputStream; | |
public class JavaZip { | |
public static void main(String[] args) throws Exception { | |
ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(args[0])); | |
for (int i = 1; i < args.length; i++) { | |
zipOutputStream.putNextEntry(new ZipEntry(args[i])); | |
FileInputStream inputStream = new FileInputStream(args[i]); | |
for (int read = 0; (read = inputStream.read()) != -1;) { | |
zipOutputStream.write(read); | |
} | |
zipOutputStream.closeEntry(); | |
} | |
zipOutputStream.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Klaus, criei um novo gist com um exemplo: https://gist.github.com/1596238