Get a list of resources from classpath directory

前端 未结 14 917
予麋鹿
予麋鹿 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:04

    Used a combination of Rob's response.

    final String resourceDir = "resourceDirectory/";
    List files = IOUtils.readLines(Thread.currentThread().getClass().getClassLoader().getResourceAsStream(resourceDir), Charsets.UTF_8);
    
    for(String f : files){
      String data= IOUtils.toString(Thread.currentThread().getClass().getClassLoader().getResourceAsStream(resourceDir + f));
      ....process data
    }
    

提交回复
热议问题