2012-04-04 107 views
0

是否可以打開zip文件並使用它作爲文件夾。我需要一次從hunders部分解壓ZIP文件內的一個文件夾。標準迭代是非常慢的(假設我需要打開ID = 432的文件夾,因此431文件夾將在之前檢查)。有什麼辦法可以部分快速地從zip壓縮一些數據?Android - 打開ZIP作爲文件夾

感謝

回答

2

看到這個例子它可能對你有幫助。

public void unzip() { 
        try { 
        FileInputStream fin = new FileInputStream(_zipFile); 
        ZipInputStream zin = new ZipInputStream(fin); 
        ZipEntry ze = null; 
        while ((ze = zin.getNextEntry()) != null) { 
         Log.v("Decompress", "Unzipping " + ze.getName()); 
         System.out.println("^^^^^^UnzippingFile^"+ze.getName()); 
         ///code to search is given string exists or not in a Sentence 
         String haystack = ze.getName(); 
         String needle1 = ".DS_Store"; 
         int index1 = haystack.indexOf(needle1); 
         if (index1 != -1) 
         { 
          System.out.println("The string contains the substring " 
+ needle1); 
          continue; 
         } 
         /*else 
          System.out.println("The string does not contain the 
substring " + needle1);*/ 


         if(ze.isDirectory()) { 
         _dirChecker(ze.getName()); 
         } else { 
         FileOutputStream fout = new FileOutputStream(_location + 
ze.getName()); 
         // replace for loop with: 
         byte[] buffer = new byte[1024]; 
         int length; 
         while ((length = zin.read(buffer))>0) { 
         fout.write(buffer, 0, length); 
         } 

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




        }////Outer While 
        zin.close(); 
        } catch(Exception e) { 
        Log.e("Decompress", "unzip", e); 
        } 

       } 

       private void _dirChecker(String dir) { 
        File f = new File(_location + dir); 

        if(!f.isDirectory()) { 
        f.mkdirs(); 
        } 
       } 
0

看看getEntry方法上ZipFilehere