Getting a directory inside a .jar

后端 未结 8 1494
悲哀的现实
悲哀的现实 2020-12-11 04:48

I am trying to access a directory inside my jar file. I want to go through every of the files inside the directory itself. I tried, for example, using the following:

<
8条回答
  •  暖寄归人
    2020-12-11 04:54

    IF you really want to treat JAR files like directories, then please have a look at TrueZIP 7. Something like the following might be what you want:

    URL url = ... // whatever
    URI uri = url.toURI();
    TFile file = new TFile(uri); // File-look-alike in TrueZIP 7
    if (file.isDirectory) // true for regular directories AND JARs if the module truezip-driver-file is on the class path
        for (TFile entry : file.listFiles()) // iterate top level directory
             System.out.println(entry.getPath()); // or whatever
    

    Regards, Christian

提交回复
热议问题