既存の zip ファイルにイメージを追加するためのユーティリティを 1 つ開発しています。ほとんどの場合、肯定的な結果が得られます。しかし、同じ場合、ユーティリティは次のエラーをスローします
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)
ファイルもubuntuの解凍ツールで解凍しません。次のようにエラーが表示されます
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を使用しています。
この問題の解決にご協力ください。