Skip to content

Instantly share code, notes, and snippets.

@tindzk
Forked from Swind/ZipArchive.scala
Last active July 24, 2018 13:55
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 tindzk/add23143aab5194b7d5a770135284f97 to your computer and use it in GitHub Desktop.
Save tindzk/add23143aab5194b7d5a770135284f97 to your computer and use it in GitHub Desktop.
Unzip file
object ZipArchive {
def unZip(source: File, targetFolder: File): Unit = {
val zipFile = new ZipFile(source)
try
zipFile.entries.asScala.foreach { entry =>
val target = new File(targetFolder, entry.getName)
if (entry.isDirectory) target.mkdirs()
else {
target.getParentFile.mkdirs()
val in = zipFile.getInputStream(entry)
val out = new FileOutputStream(target)
IOUtils.copy(in, out)
IOUtils.closeQuietly(in)
out.close()
}
}
finally zipFile.close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment