在gradle中使用的时候碰到了上边的错误,原本的代码如下
def tmp = File.createTempFile("temp_${System.nanoTime()}", '.zip')
tmp.withOutputStream { os ->
def zos = new ZipOutputStream(os)
zin.entries().each { entry ->
def isReplaced = entry.name == zipEntry
println("isReplaced->"+isReplaced)
if(isReplaced) {
entry.setComment(newContent)
}
zos.putNextEntry(entry)
zos << (zin.getInputStream(entry).bytes)
zos.closeEntry()
}
zos.close()
}
zin.close()
新代码如下
def tmp = File.createTempFile("temp_${System.nanoTime()}", '.zip')
tmp.withOutputStream { os ->
def zos = new ZipOutputStream(os)
zin.entries().each { entry ->
ZipEntry newZipEntry = new ZipEntry(entry.getName())
def isReplaced = newZipEntry.name == zipEntry
println("isReplaced->"+isReplaced)
if(isReplaced) {
newZipEntry.setComment(newContent)
}
zos.putNextEntry(newZipEntry)
zos << (zin.getInputStream(newZipEntry).bytes)
zos.closeEntry()
}
zos.close()
}
zin.close()
这篇博客讨论了在Gradle中遇到的一个问题,即在处理Zip文件时遇到的错误。原始代码尝试修改ZipEntry的注释,但在新代码中,创建了一个新的ZipEntry对象来实现这一目标。博主通过对比新旧代码,展示了如何更正问题,确保能正确设置ZipEntry的注释,并详细输出了判断和处理过程。这对于理解Gradle中操作Zip文件的方法和处理类似问题具有参考价值。
1957

被折叠的 条评论
为什么被折叠?



