2012-04-04 1 views
0

ist es möglich, Zip-Datei zu öffnen und handelt damit, wie es ein Ordner war. Ich muss teilweise einen Ordner in ZIP-Datei von honders auf einmal entpacken. Die Standard-Iteration ist sehr langsam (vorausgesetzt, ich muss den Ordner mit ID = 432 öffnen, damit 431 Ordner vorher geprüft werden). Gibt es einen Ansatz, den ich teilweise und schnell einige Daten von Zip entzippen kann?Android - Öffnen ZIP als Ordner

Dank

Antwort

2

In diesem Beispiel kann es Ihnen helfen.

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

Schauen Sie sich auf getEntry Methode auf ZipFilehere.