I have a spring boot project that is deployed on Tomcat 6. I have a list of files under project's resource directory and I am trying to list all files under that directory. I am able to get specific file if I specify classpath:abc.txt in the getResource() method. However I am wondering if there is a way to just list all files with a wild card or something.
            Asked
            
        
        
            Active
            
        
            Viewed 53 times
        
    1 Answers
0
            You cannot do like this MyClass.class.getResource('*.txt'). The alternative to this is :
ServletContext      sc                      =       request.getSession().getServletContext();
    String          strPath                 =       sc.getRealPath("/");
File[]          allFiles          =       new File(strpath).listFiles(new FilenameFilter()    {
    @Override
    public boolean accept(File dir, String name) {
        return name.toLowerCase().endsWith(".txt");
    }
});
Refer this :Using File.listFiles with FileNameExtensionFilter
        Community
        
- 1
 - 1
 
        Alok Chaudhary
        
- 3,481
 - 1
 - 16
 - 19