我使用 zip4j 解压缩由密码 (AES-256) 保护的 zip 包。我的问题不是代码不起作用,而是当密码与 .zip 上的实际密码不匹配时它不会引发任何错误。
.zip 的密码为 123,对于 zip4j,我设置了密码 123456789。所以他无法提取所有内容。我希望出现无法提取的错误或任何消息。实际情况是,他没有提取它,但没有异常或错误消息,什么都没有。
知道如何检查提取是否成功吗?
protected void unpackZip(String destinationPath, String archivePath) throws InterruptedException {
int onChange = 0;
try {
ZipFile zipFile = new ZipFile( archivePath );
zipFile.setRunInThread( true );
if (zipFile.isEncrypted()) {
zipFile.setPassword( "123456789");
}
zipFile.extractAll( destinationPath );
// http://www.lingala.net/zip4j/forum/index.php?topic=68.0
ProgressMonitor progressMonitor = zipFile.getProgressMonitor();
while (progressMonitor.getState() == ProgressMonitor.STATE_BUSY) {
// To get the percentage done
if (onChange != progressMonitor.getPercentDone()) {
onChange = progressMonitor.getPercentDone();
sendWebStatusUiMessage( "Extracted : " + onChange + "% ", "update" );
}
try {
Thread.sleep( 1000 );
} catch (Exception e) {
}
}
} catch (ZipException e) {
e.printStackTrace();
}
}