Sevenzipjbind:为什么openInArchive方法不能与RAR一起使用?

时间:2019-08-19 09:48:02

标签: java rar

库Sevenzipjbind可以在7z和zip扩展名中正常工作,但是openInArchive方法不适用于RAR,并且我看不到任何解决方案。 我要做的就是检查RAR文件是否受密码保护。

我已经在openInArchive方法中尝试了null值,该方法应该检测到文件扩展名,并且我尝试了ArchiveFormat.RAR而不是null,但它也无法正常工作。

IInArchive archiveHelper;
RandomAccessFile randomAccessFile;

randomAccessFile = new RandomAccessFile(archive, "r");
archiveHelper = SevenZip.openInArchive(null,
                          new RandomAccessFileInStream(
                                  randomAccessFile));
                  SimpleInArchiveItemImpl item= new SimpleInArchiveItemImpl(archiveHelper,0); 

if(item.isEncrypted()){
   // some code
}

“存档”是一个File对象

如果openInArchive方法中的值为空,则错误消息如下所示:

net.sf.sevenzipjbinding.SevenZipException: Archive file can't be opened with none of the registered codecs

但是如果存在ArchiveFormat.RAR而不是null,则错误消息如下所示: net.sf.sevenzipjbinding.SevenZipException HRESULT: 0x1 (FALSE). Archive file (format: Rar) can't be opened

0 个答案:

没有答案