Get a list of resources from classpath directory

前端 未结 14 888
予麋鹿
予麋鹿 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 05:56

    The Spring framework's PathMatchingResourcePatternResolver is really awesome for these things:

    private Resource[] getXMLResources() throws IOException
    {
        ClassLoader classLoader = MethodHandles.lookup().getClass().getClassLoader();
        PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(classLoader);
    
        return resolver.getResources("classpath:x/y/z/*.xml");
    }
    

    Maven dependency:

    
        org.springframework
        spring-core
        LATEST
    
    

提交回复
热议问题