zip4j Compression type not supported Exception: Android

倖福魔咒の 提交于 2019-12-12 02:37:24

问题


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:

  1. Why i am getting this exception?
  2. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!