2017-01-28 6 views
1

다른 이름의 파일이 많이 들어있는 zip 파일을 압축 해제하는 앱이 있습니다. Zip 파일의 일부 파일에는 특수 문자가 있습니다.API24의 파일 이름에 특수 문자가있는 파일의 압축을 풉니 다.

압축 해제는 API 23을 사용하는 모든 기기에서 효과적이었습니다.

API 24 및 API 25를 사용하면 일부 파일을 압축하지 못하지만 특정 파일 (이름) -> chotedteau_thierry (1814) .jpa의 압축을 해제 할 때 Zip 형식의 오류가 발생합니다. 그 안에)

지퍼를 조작하지 않고 어떻게 특수 문자로 파일을 압축 해제 할 수 있습니까? 이미 API가 24 미만인 경우 이미 작동했음을 의미합니다.

나를 도와 줄 수 있습니까?

 ZipFile zipFile = new ZipFile(zipname); 
     Enumeration enumeration = zipFile.entries(); 

     while (enumeration.hasMoreElements()) { 

      ZipEntry zipEntry = null; 
      zipEntry = (ZipEntry) enumeration.nextElement(); <----- Craches, when it comes to the file : battle of chÔteau_thierry (1814).jpa 
      String sName = zipEntry.getName(); 
} 

* ZipFile에로 업데이트 *

링크 : https://drive.google.com/file/d/0BzTzuiIaUzqkd3loR2dPdW03T28/view?usp=sharing

당신은 구글 드라이브가 묵시적으로 파일 이름을 변환하기 때문에, 로컬 파일을 다운로드해야합니다. (chateau_thierry (1814) .jpa, french의 전투) 당신은 단지 로컬 zipfile의 Ô 문자 만 보았습니다.

Hint : java.lang.IllegalArgumentException: MALFORMED[1] 
at java.util.zip.ZipCoder.toString(ZipCoder.java:65) 
at java.util.zip.ZipFile.getZipEntry(ZipFile.java:548) 
at java.util.zip.ZipFile.-wrap2(ZipFile.java) 
at java.util.zip.ZipFile$1.nextElement(ZipFile.java:530) 
at java.util.zip.ZipFile$1.nextElement(ZipFile.java:508) 
at solveraapps.chronicbrowser.ChronicBrowser.unzipImages(ChronicBrowser.java:8011) 
at solveraapps.chronicbrowser.ChronicBrowser$16.run(ChronicBrowser.java:8442) 
+0

크래시의 Java 스택 추적은 무엇입니까? 문제를 나타내는 샘플 ZIP 파일을 업로드 할 수 있습니까? – CommonsWare

+0

도움을 주셔서 감사합니다. 방금 zipfile 및 스택 추적을 참조하여 질문을 업데이트했습니다. 또한 일부 코드를 추가하여 재현하기 위해 붙여 넣을 수 있습니다. 고마워. –

+0

ZIP 아카이브에는'chÔteau.jpg'라는 파일이 없습니다. – CommonsWare

답변

0

내가 happely 지금 그것을 해결하고 내가 너무 upvoter을 도울 수 있기를 바랍니다 : 만 API 24 개 & 25 장치를 얻을

스택 트레이스,?

API가 Nougat에서 ZipFile과 관련하여 변경되었습니다. 다큐에서

ZipFile(String name, Charset charset) // Charset only when >=24 

는 SAIS :

The UTF-8 charset is used to decode the entry names and comments 

그래서 내 코딩 솔루션을 "ISO-8859-1 올바른 Characterset을 설정하는 것입니다 ZipFile를 구축 할 때 24에서 위쪽으로 당신은 캐릭터 세트를 지정할 수 있습니다 ":

@TargetApi(24) 
public void myUnzipper(){ 

      ZipFile zipFile = null; 
      if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){ // N for Nougat 
       zipFile = new ZipFile(zipname,Charset.forName("ISO-8859-1")); 
      }else{ 
       zipFile = new ZipFile(zipname); 
      } 

      while (enumeration.hasMoreElements()) { 

       ZipEntry zipEntry = null; 
       zipEntry = (ZipEntry) enumeration.nextElement(); <----- Craches, when it comes to the file : battle of chÔteau_thierry (1814).jpa 
       String sName = zipEntry.getName(); 
      } 

}