首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何检查该文件是否存在于zip存档中?

如何检查该文件是否存在于zip存档中?
EN

Stack Overflow用户
提问于 2015-09-07 10:03:10
回答 2查看 6.6K关注 0票数 6

如何检查该文件是否存在于zip存档中?

例如,检查app.apk是否包含classes.dex

我想找到一个使用JavaNIO.2 Path的解决方案,如果可能的话,不需要提取整个归档文件。

我试过了,但没有用:

代码语言:javascript
复制
Path classesFile = Paths.get("app.apk", "classes.dex");  // apk file with classes.dex
if (Files.exists(apkFile))  // false!
    ...
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-09-07 10:13:31

我的解决办法是:

代码语言:javascript
复制
Path apkFile = Paths.get("app.apk");
FileSystem fs = FileSystems.newFileSystem(apkFile, null);
Path dexFile = fs.getPath("classes.dex");
if (Files.exists(dexFile))
    ...
票数 5
EN

Stack Overflow用户

发布于 2021-08-06 13:33:47

另一个例子是:

代码语言:javascript
复制
      try {

         //open the source zip file
         ZipFile sourceZipFile = new ZipFile(f);

         //File we want to search for inside the zip file
         String searchFileName = "TEST.TXT";

         //get all entries
         Enumeration e = sourceZipFile.entries();
         boolean found = false;

         System.out.println("Trying to search " + searchFileName + " in " + sourceZipFile.getName());

         while(e.hasMoreElements())
         {
            ZipEntry entry = (ZipEntry)e.nextElement();

            if(entry.getName().indexOf(searchFileName) != -1)
            {

               found = true;
               System.out.println("Found " + entry.getName());

            }
         }

         if(found == false)
         {
            System.out.println("File " + searchFileName + " Not Found inside ZIP file " + sourceZipFile.getName());
         }

         //close the zip file
         sourceZipFile.close();
      }
      catch(IOException ioe) {
         System.out.println("Error opening zip file" + ioe);
      }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32435953

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档