Groovy Zip 文件

new File(sourceZipPath).eachFile() { file ->
    println "开始处理文件 ${file.name}"
    if (file.isFile()) {
        if (file.name.endsWith(".apk")) {
            // 为 apk 生成注释文件
            def fileSize = String.format("%.2f", file.size() / 1024 / 1024)
            comment.append("文件: ${file.name}\n")
                    .append("大小:  ${fileSize} MB\n")
                    .append("MD5: ${file.getBytes().md5()}\n")
                    .append("\n")
        }
        zipFile.putNextEntry(new ZipEntry(file.name))
        zipFile.write(file.getBytes())
        zipFile.closeEntry()
    }
}
println "注释信息为:\n $comment"
zipFile.comment = comment
zipFile.close()