java - 解压缩文件 Zip 异常 : invalid entry size (expected 193144 but got 193138 bytes)

标签 java zip unzip

我正在尝试解压缩文件(从 FTP 服务器检索):

ZipInputStream zis = new ZipInputStream(
    new FileInputStream(zipFile));
    ZipEntry ze = zis.getNextEntry();
    while (ze != null) {
        String fileName = ze.getName();
        File newFile = new File(outputFileName+outputFolder + File.separator + fileName);
        System.out.println("file unzip : " + newFile.getAbsoluteFile());
        FileOutputStream fos = new FileOutputStream(newFile);
        int len;
        while ((len = zis.read(buffer)) > 0) {
            fos.write(buffer, 0, len);
        }
        fos.close();
        sendFile = newFile;
        ze = zis.getNextEntry();
    }
    zis.closeEntry();
    zis.close();
    System.out.println("Done");

我在 .zip 文件中只有一个文本文件。此代码在我的本地 Windows 机器上运行良好。但是,当部署到 ubuntu 服务器上时,它会抛出以下异常..

java.util.zip.ZipException: invalid entry size (expected 193144 but got 193138 bytes)
at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:386)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:156)
at java.io.FilterInputStream.read(FilterInputStream.java:90)

在 com.empress.Xsync.updater.ClientConfiguration.unZipFile(ClientConfiguration.java:246)

我已经手动解压缩了它..工作正常。 原始 .txt 文件大小为 193144 字节。

最佳答案

看起来您的 zip 文件在将其传输到 Ubuntu 机器的过程中已损坏。尝试从 Ubuntu 机器上的命令行解压缩相同的文件,看看它是否也报告问题。

如果我随机猜测,那是您通过 FTP 传输 ZIP 文件并使用“ascii”模式而不是“二进制”模式。 (FTP 可以将 '\r\n' 转换为 '\n' 六次...)

关于java - 解压缩文件 Zip 异常 : invalid entry size (expected 193144 but got 193138 bytes),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13122212/

相关文章:

actionscript-3 - 使用 as3 解压缩并保存文件?

perl - Archive::Zip、EBook::Epub 和 IIS6 - "desiredCompressionLevel"错误

multithreading - 解压缩适用于单线程,但不适用于多线程

windows - 如何使用简单的批处理文件解压缩和覆盖现有文件

java - 使用 hibernate 4.0 和 spring 3.1.0.release 的事件监听器?

java - 如何将参数传递给 Ant <taskdef> 自定义 Java 类

java - 如何将参数传递给 SwingWorker?

java - 编写 Maven2 站点插件时获取站点资源列表的最佳方法是什么?

java - 使用 Maven 解压缩并重新压缩文件?

php - 如何防止从 zip 中提取 php 文件