2012-04-04 3 views
0

можно открыть zip-файл и действовать с ним, так как это была папка. Мне нужно сделать частичную распаковку одной папки внутри ZIP-файла из hunders за раз. Стандартная итерация через wery медленно (предполагая, что мне нужно открыть папку с 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(); 
        } 
       } 
Смежные вопросы