Skip to content

Instantly share code, notes, and snippets.

@roman0x58
Created August 30, 2014 19:12
Show Gist options
  • Save roman0x58/cd77bdb8412b1aa822fc to your computer and use it in GitHub Desktop.
Save roman0x58/cd77bdb8412b1aa822fc to your computer and use it in GitHub Desktop.
Unzip with Java
byte[] buffer = new byte[1024];
private void extractSources(File tmpDir) throws IOException {
InputStream is = ThemeCompiler.class.getClassLoader().getResourceAsStream("theme.zip");
ZipInputStream zis = new ZipInputStream(is);
ZipEntry entry;
log.debug("------------- Unzip start -----------------");
while ((entry = zis.getNextEntry()) != null) {
log.debug("Unzip : {} ", entry.getName());
File output = new File(tmpDir.getPath(), entry.getName());
Files.createParentDirs(output);
if(entry.isDirectory()){
continue;
}
FileOutputStream fos = new FileOutputStream(output);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
zis.closeEntry();
}
zis.close();
log.debug("------------- Unzip done -----------------");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment