Unzip Archive with Groovy

前端 未结 9 1183
深忆病人
深忆病人 2020-12-15 04:00

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 ?

9条回答
  •  有刺的猬
    2020-12-15 04:43

    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
    }
    

提交回复
热议问题