java - How to load all files of a folder to a list of Resources in Spring? -
i have folder , want load txt files list using spring , wildcards:
by annotation following:
@value("classpath*:../../dir/*.txt") private resource[] files;   but how can achieve same using spring pragmatically?
use resourceloader , resourcepatternutils:
class foobar {     private resourceloader resourceloader;      @autowired     public foobar(resourceloader resourceloader) {         this.resourceloader = resourceloader;     }      resource[] loadresources(string pattern) throws ioexception {         return resourcepatternutils.getresourcepatternresolver(resourceloader).getresources(pattern);     } }   and use like:
resource[] resources = foobar.loadresources("classpath*:../../dir/*.txt");      
Comments
Post a Comment