Я разработал одну утилиту для добавления изображения в существующий zip-файл. В большинстве случаев я получаю положительный результат. но в том же случае ошибка сброса полезностиПочтовые индексы не найдены. вероятно, не zip-файл
Почтовые индексы не найдены. вероятно, не zip-файл
, но файл открыт в «диспетчере архива» или winrar. мой код выглядит следующим образом:
public static boolean addFileIntoZip(String sourceFile, String zipFile) {
try {
logger.debug("add file in Zip>>>>>>>>>>");
logger.debug("Source Folder {} and Destination Folder {}", sourceFile, zipFile);
ZipFile file = new ZipFile(zipFile);
File sFile = new File(sourceFile);
// Initiate Zip Parameters which define various properties such
// as compression method, etc.
ZipParameters parameters = new ZipParameters();
// set compression method to store compression
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
// Set the compression level
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
file.addFile(sFile, parameters);
return true;
} catch (ZipException e) {
e.printStackTrace();
}
return false;
}
стек ошибка
2016-11-03 15:55:39 [DEBUG] (ZipUtil.java:121) => add file in Zip>>>>>>>>>>
2016-11-03 15:55:39 [DEBUG] (ZipUtil.java:122) => Source Folder /home/sanjeet/Downloads/DocumentViewer_architecture.png and Destination Folder /home/sanjeet/Downloads/tst/000033541066253_D.zip
net.lingala.zip4j.exception.ZipException: zip headers not found. probably not a zip file
at net.lingala.zip4j.core.HeaderReader.readEndOfCentralDirectoryRecord(HeaderReader.java:122)
at net.lingala.zip4j.core.HeaderReader.readAllHeaders(HeaderReader.java:78)
at net.lingala.zip4j.core.ZipFile.readZipInfo(ZipFile.java:425)
at net.lingala.zip4j.core.ZipFile.checkZipModel(ZipFile.java:935)
at net.lingala.zip4j.core.ZipFile.addFiles(ZipFile.java:263)
at net.lingala.zip4j.core.ZipFile.addFile(ZipFile.java:250)
at com.grit.docs.util.ZipUtil.addFileIntoZip(ZipUtil.java:135)
at com.grit.docs.util.ZipUtil.main(ZipUtil.java:160)
файл также не разворачивайте на распакованный инструмент в убунту. он показывает ошибку как
Archive: 000033541066253_D.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of 000033541066253_D.zip or
000033541066253_D.zip.zip, and cannot find 000033541066253_D.zip.ZIP, period.
Я использую zip4j zip lib.
Просьба помочь устранить эту проблему.