2014-06-23 3 views
0

다음 압축 해제 기능이 모든 zip 파일에서 작동하지 않습니다. ZIP 파일은 하나 개의 XML 파일을 하나 개의 폴더 (이름 - "이미지")를 포함Android unzip 기능이 작동하지 않습니다.

  1. follows-로

    내 zip 파일 패턴입니다.

  2. xml 파일의 이름은 zip 파일 이름과 동일합니다.
  3. 폴더 ("images")는 파일을 포함 할 수도 있고 포함하지 않을 수도 있습니다.

xml 파일을 zip 파일로 보내기 전에 유효성을 검사했습니다.

public boolean unZip(String path) 
{  
    InputStream is; 
    ZipInputStream zis; 
    try 
    { 
     String filename; 
     is = new FileInputStream(path); 
     zis = new ZipInputStream(new BufferedInputStream(is)); 
     ZipEntry ze; 
     byte[] buffer = new byte[1024]; 
     int count; 

     while ((ze = zis.getNextEntry()) != null) 
     { 
      filename = ze.getName(); 
      if (ze.isDirectory()) { 
       File fmd = new File(path.substring(0,path.length()-4)+"/"+filename); 
       fmd.mkdirs(); 
       continue; 
      } 

      FileOutputStream fout = new FileOutputStream(path.substring(0,path.length()-4)+"/"+filename); 

      while ((count = zis.read(buffer)) != -1) 
      { 
       fout.write(buffer, 0, count);    
      } 

      fout.close();    
      zis.closeEntry(); 
     } 

     zis.close(); 
    } 
    catch(IOException e) 
    { 
     e.printStackTrace(); 
     return false; 
    } 

    return true; 
} 

Exception at Logcat view

+0

'mkdirs()'는 성공하면 true를 반환하고 실패하면 false를 반환합니다. 이 값의 유효성을 검사하고 메소드가 실패한 이유를 이해하려고 시도하십시오. – AlexR

+0

> 고맙습니다.하지만 부모님, 루프 처음에는 XML 파일 이름을 "파일 이름"변수로 설정합니다. 그런 다음 if 부분을 건너 뛰고 직접 "FileOutputStream fout = new FileOutputStream (path.substring (0, path.length() - 4) +"/ "+ filename);" 행과 예외를 throw합니다. – JohnC

+0

이것은'ze'가 디렉토리가 아님을 의미합니다. – AlexR

답변

1

이 방법은 잘 작동 : 그것은 어떤 압축이 행에서 예외를 발생

함수이다

FileOutputStream fout = new ileOutputStream(path.substring(0,path.length()-4)+"/"+filename); 

를 파일 -. Linux 플랫폼에서 zip을 만드는 동안 권한 문제가있었습니다. 그러나 파일 권한을 변경하면 기능이 제대로 작동하기 시작합니다.

관련 문제