我試圖解壓文件(從FTP服務器檢索):解鏈文件ZIP異常:無效的條目大小(預期193144卻得到了193138個字節)
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字節。
它可能與問題無關,但是'InputStream.read(...)'在EOF處返回'-1'並且可以返回0 '沒有錯誤,所以你應該檢查'> = 0'或'!= -1',而不是'> 0'。 –
也試過了..沒有解決問題! – simpleJack