zip4j
zip4j copied to clipboard
Adding a file to an existing zip can lead to corruption of the zip file
A zip file has a data descriptor, and when a new file is added, there will be additional data at the end of the zip file.
struct ZIPDIRENTRY dirEntry[341] is the new file
struct ZIPENDLOCATOR endLocator[0] is the End of central directory record of the new zip
struct ZIPDIRENTRY dirEntry[342] is the is the last file of the old zip
struct ZIPENDLOCATOR endLocator[1] is the End of central directory record of the old zip
struct ZIPDIRENTRY dirEntry[342] and struct ZIPENDLOCATOR endLocator[1] are redundant
Below is my code
net.lingala.zip4j.ZipFile zipFile = null;
try {
zipFile = new ZipFile(args[0]);
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(CompressionMethod.DEFLATE);
parameters.setCompressionLevel(CompressionLevel.NORMAL);
parameters.setFileNameInZip("assets/neoptionBin");
zipFile.addFile(info, parameters);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (zipFile != null) {
zipFile.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}