0

zipファイルを開いて、フォルダのように操作することは可能ですか。一度に何百ものファイルからZIPファイル内の1つのフォルダーを部分的に解凍する必要があります。標準の反復処理は非常に遅いです(ID = 432のフォルダーを開く必要があると想定しているため、431個のフォルダーが前にチェックされます)。一部のデータをzipから部分的かつ迅速に解凍できるアプローチはありますか?

ありがとう

4

2 に答える 2

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();
                   }
                 }
于 2012-04-04T08:21:34.083 に答える
0

こちらgetEntryの方法をご覧ください。ZipFile

于 2012-04-04T08:16:50.583 に答える