2015-09-07 76 views
3

如何檢查該文件是否存在於一個zip檔案中?
例如,檢查app.apk是否包含classes.dex
我想找到一個解決方案,它使用Java NIO.2 Path,並且在可能的情況下無需提取整個存檔。如何檢查該文件是否存在於一個zip檔案中?

我試着和它沒有工作:

Path classesFile = Paths.get("app.apk", "classes.dex"); // apk file with classes.dex 
if (Files.exists(apkFile)) // false! 
    ... 

回答

2

我的解決辦法是:

Path apkFile = Paths.get("app.apk"); 
FileSystem fs = FileSystems.newFileSystem(apkFile, null); 
Path dexFile = fs.getPath("classes.dex"); 
if (Files.exists(dexFile)) 
    ... 
1

您可以嘗試ZipInputStream。用法如下: -

ZipInputStream zip = new ZipInputStream(Files.newInputStream(
      Paths.get(
        "path_to_File"), 
      StandardOpenOption.READ)); 
    ZipEntry entry = null; 

    while((entry = zip.getNextEntry()) != null){ 
     System.out.println(entry.getName()); 
    } 
+1

This Works,thanks。 – Mauker

相關問題