Tôi cố gắng để giải nén một tập tin (lấy từ một máy chủ FTP):giải nén file Zip Ngoại lệ: kích thước entry không hợp lệ (dự kiến 193.144 nhưng có 193.138 byte)
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");
Tôi chỉ có một tập tin văn bản trong. tệp zip. Mã này hoạt động tốt trên máy cửa sổ cục bộ của tôi. Tuy nhiên, khi triển khai vào máy chủ ubuntu, nó ném ngoại lệ sau ..
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)
tại com.empress.Xsync.updater.ClientConfiguration.unZipFile (ClientConfiguration.java:246)
tôi đã tự giải nén nó ..hoạt động tốt. Kích thước tệp .txt Gốc là 193144 byte.
Nó có thể không liên quan gì đến vấn đề này, nhưng 'InputStream.read (...)' trả về '-1' tại EOF và có thể trả về' 0 'không có lỗi, vì vậy bạn nên kiểm tra'> = 0' hoặc '! = -1', không phải'> 0'. –
Cố gắng mà quá .. Đã không giải quyết được vấn đề !! – simpleJack