How can I discover resources in a Java jar with a wildcard name?

前端 未结 5 538
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-18 02:55

I want to discover all xml files that my ClassLoader is aware of using a wildcard pattern. Is there any way to do this?

5条回答
  •  清酒与你
    2021-01-18 03:37

    A JAR-file is just another ZIP-file, right?

    So I suppose you could iterate the jar-files using http://java.sun.com/javase/6/docs/api/java/util/zip/ZipInputStream.html

    I'm thinking something like:

    ZipSearcher searcher = new ZipSearcher(new ZipInputStream(new FileInputStream("my.jar"))); List xmlFilenames = searcher.search(new RegexFilenameFilter(".xml$"));

    Cheers. Keith.

提交回复
热议问题