Unzip Archive with Groovy

前端 未结 9 1222
深忆病人
深忆病人 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 04:41

    In my experience, the best way to do this is to use the Antbuilder:

    def ant = new AntBuilder()   // create an antbuilder
    
    ant.unzip(  src:"your-src.zip",
                dest:"your-dest-directory",
                overwrite:"false" )
    

    This way you aren't responsible for doing all the complicated stuff - ant takes care of it for you. Obviously if you need something more granular then this isn't going to work, but for most 'just unzip this file' scenarios this is really effective.

    To use antbuilder, just include ant.jar and ant-launcher.jar in your classpath.

提交回复
热议问题