Get a list of resources from classpath directory

前端 未结 14 902
予麋鹿
予麋鹿 2020-11-22 05:20

I am looking for a way to get a list of all resource names from a given classpath directory, something like a method List getResourceNames (String direct

14条回答
  •  囚心锁ツ
    2020-11-22 06:14

    My way, no Spring, used during a unit test:

    URI uri = TestClass.class.getResource("/resources").toURI();
    Path myPath = Paths.get(uri);
    Stream walk = Files.walk(myPath, 1);
    for (Iterator it = walk.iterator(); it.hasNext(); ) {
        Path filename = it.next();   
        System.out.println(filename);
    }
    

提交回复
热议问题