Unzip Archive with Groovy

HaBaLeS picture HaBaLeS · Mar 14, 2009 · Viewed 40.4k times · Source

is there a built-in support in Groovy to handle Zip files (the groovy way)?

Or do i have to use Java's java.util.zip.ZipFile to process Zip files in Groovy ?

Answer

Chad Gorshing picture Chad Gorshing · Aug 15, 2009

Maybe Groovy doesn't have 'native' support for zip files, but it is still pretty trivial to work with them.

I'm working with zip files and the following is some of the logic I'm using:

def zipFile = new java.util.zip.ZipFile(new File('some.zip'))

zipFile.entries().each {
   println zipFile.getInputStream(it).text
}

You can add additional logic using a findAll method:

def zipFile = new java.util.zip.ZipFile(new File('some.zip'))

zipFile.entries().findAll { !it.directory }.each {
   println zipFile.getInputStream(it).text
}