2012-08-01 84 views
2

我想解壓縮部分分割的文件(file.part1,file.part2,file.part3 ...)。 我把所有的部件放在同一個文件夾中。在互聯網上,我只找到了解壓縮單個文件的例子。Android:如何解壓縮部分分割的文件

有人知道是否有API來做到這一點?

回答

2

壓縮API在Android上的Java AFAIK上沒有變化。在Java中,您可以輕鬆地解壓縮多卷文件。我發佈了一些Java代碼,您應該可以在Android上運行一些小的(如果有的話)修改。

public class Main { 

public static void main(String[] args) throws IOException { 
    ZipInputStream is = new ZipInputStream(new SequenceInputStream(Collections.enumeration(
     Arrays.asList(new FileInputStream("test.zip.001"), new FileInputStream("test.zip.002"), new FileInputStream("test.zip.003"))))); 
    try { 
     for(ZipEntry entry = null; (entry = is.getNextEntry()) != null;) { 
      OutputStream os = new BufferedOutputStream(new FileOutputStream(entry.getName())); 
      try { 
       final int bufferSize = 1024; 
       byte[] buffer = new byte[bufferSize]; 
       for(int readBytes = -1; (readBytes = is.read(buffer, 0, bufferSize)) > -1;) { 
        os.write(buffer, 0, readBytes); 
       } 
       os.flush(); 
      } finally { 
       os.close(); 
      } 
     } 
    } finally { 
     is.close(); 
    } 
} 

}

的代碼是從較舊的SO問題,其可以被發現here

+0

它的工作原理,謝謝! – PauloBueno 2012-08-02 20:43:22