-
-
Save tindzk/add23143aab5194b7d5a770135284f97 to your computer and use it in GitHub Desktop.
Unzip file
This file contains hidden or 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
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