zip4j: net.lingala.zip4j.exception.ZipException: Expected central directory entry not found (#1)
For some zip file, I can execute ZipFile.addFile() successfully. But for other zip file, error happened: I can execute ZipFile.addFile() without any error; But after that, when I open the zipFile, I do not find the file I added to the zipFile; And I can not open the zipFile(after execute ZipFile.addFile) by zip4j, Exception happened.
Exception:
net.lingala.zip4j.exception.ZipException: Expected central directory entry not found (#1)
at net.lingala.zip4j.headers.HeaderReader.readCentralDirectory(HeaderReader.java:156)
at net.lingala.zip4j.headers.HeaderReader.readAllHeaders(HeaderReader.java:86)
at net.lingala.zip4j.ZipFile.readZipInfo(ZipFile.java:851)
at net.lingala.zip4j.ZipFile.addFiles(ZipFile.java:283)
at net.lingala.zip4j.ZipFile.addFile(ZipFile.java:244)
at com.dancen.util.filecompressor.MyZipUtil.main(MyZipUtil.java:43)
testCode:
public static void main(String[] args)
{
try
{
String zipFilePath = "C:\\Users\\zhang\\Desktop\\pro.apk";
String filePathInZip = "lib/test/test.so";
String filePath = "apk/lib/x86/libArmArchEncrypt.so";
ZipParameters zipParameters = new ZipParameters();
zipParameters.setCompressionMethod(CompressionMethod.DEFLATE);
zipParameters.setCompressionLevel(CompressionLevel.NORMAL);
zipParameters.setFileNameInZip(filePathInZip);
zipParameters.setOverrideExistingFilesInZip(true);
ZipFile zipFile = new ZipFile(zipFilePath);
zipFile.addFile(new File(filePath), zipParameters);
}
catch(Exception e)
{
e.printStackTrace();
}
}
Test Again, I change the zipParameters, setCompressionMethod as CompressionMethod.STORE, Now everything OK.
TestCode:
public static void main(String[] args)
{
try
{
String zipFilePath = "C:\\Users\\zhang\\Desktop\\pro.apk";
String filePathInZip = "lib/test/test.so";
String filePath = "apk/lib/x86/libArmArchEncrypt.so";
ZipParameters zipParameters = new ZipParameters();
zipParameters.setCompressionMethod(CompressionMethod.STORE);
zipParameters.setFileNameInZip(filePathInZip);
zipParameters.setOverrideExistingFilesInZip(true);
ZipFile zipFile = new ZipFile(zipFilePath);
zipFile.addFile(new File(filePath), zipParameters);
}
catch(Exception e)
{
e.printStackTrace();
}
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 16 (5 by maintainers)
Commits related to this issue
- #117 Write existing extra data records when adding files to zip — committed to srikanth-lingala/zip4j by srikanth-lingala 7 years ago
Same issue when calling the .extractAll() method. Could you fix it?
Fixed in v2.2.8 released today
I have updated the comment by attach the test files, And my system is windows 10.