栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java.util.zip.zipexception invalid entry compressed size (expected 36586 but got 37005 bytes)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java.util.zip.zipexception invalid entry compressed size (expected 36586 but got 37005 bytes)

在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()
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/874485.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号