问题
I am trying to unzip a password protected zip file using zip4j library for android. But it is giving Unsupported Compression Type exception. I have searched a lot but could not find any reason or solution for it.
So my questions are:
- Why i am getting this exception?
How to solve this problem? Should i use any other library?
try { File src = new File("/sdcard/" + filename); ZipFile zipFile = new ZipFile(src); if (zipFile.isEncrypted()) { zipFile.setPassword("mypassword"); } File destFile=new File ("/sdcard/tests_images_Xdata"); if(!destFile.isDirectory()){ destFile.mkdir(); String dest = new String("/sdcard/tests_images_Xdata"); zipFile.extractAll(dest); } } catch (ZipException e) { e.printStackTrace(); }
回答1:
First I think there exists some errors in your code,
if(!destFile.isDirectory()){
is only true when the destFile is a file, and second you must set your compressed file with the suffix "zip", that is means your variable filename must contains ".zip".
回答2:
Zip4j supports Store (no compression) or Deflate compression algorithms. Most probably, the zip file for which you have this problem is compressed using some other compression algorithm that is not supported by Zip4j.
To see the compression type of a file in a zip file, open the zip file in 7-Zip -> right click on a file -> Properties. The field containing "Method" shows you the compression type used.
To use a zip file with zip4j, you have to make sure that it is compressed using either deflate or Store (no compression)
来源:https://stackoverflow.com/questions/20238537/zip4j-compression-type-not-supported-exception-android