Unzipping file Zip Exception: invalid entry size (expected 193144 but got 193138 bytes)

杀马特。学长 韩版系。学妹 提交于 2020-01-02 02:43:07

问题


I am trying to unzip a file (retrieved from an FTP server):

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");

I have only one text file in the .zip file. This code works fine on my local windows machine. However, when deployed onto ubuntu server, it throws the following exception..

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)

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

I have manually unzipped it..works fine. Original .txt file size is 193144 bytes.


回答1:


It looks like your zip file has been corrupted in the process of transferring it to the Ubuntu machine. Try unzipping the same file from the command line on the Ubuntu machine to see if it also reports problems.

If I was to make a random guess, it would be that you transferred the ZIP file via FTP and used 'ascii' mode instead of 'binary' mode. (FTP could have converted '\r\n' to '\n' six times ...)



来源:https://stackoverflow.com/questions/13122212/unzipping-file-zip-exception-invalid-entry-size-expected-193144-but-got-193138

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!