0

I am trying to load the entire Mappings folder (which has subfolders and subfolders have files) into the classpath and then want to iterate and find specific files using a hashmap. Using classpath I am able to find the file which is directly loaded under the resources folder but I don't want it that way. Below is my code:

public class ClassPathProblem {
    public static void main(String[] ar) throws Exception {
        ClassPathProblem cp = new ClassPathProblem();
        cp.loadResource("/Encounter.properties");
    }
    private void loadResource(String resource) throws IOException {
        URL u = this.getClass().getResource(resource);
        loadResourceByUrl(u, resource);
    }
    private void loadResourceByUrl(URL u, String resource) throws IOException {
        System.out.println("-> attempting input resource: " + resource);
        if (u != null) {
            String path = u.getPath();
            path = path.replaceFirst("^/(.:/)", "$1");
            System.out.println("    absolute resource path found :\n    " + path);
            String s = new String(Files.readAllBytes(Paths.get(path)));
            System.out.println("    file content: " + s);
        } else {
            System.out.println("    no resource found: " + resource);
        }
    }
}  

Below is my project structure for resources:

enter image description here

When I run the program for the input passed it returns the properties file which is loaded directly into the resources folder which is "Encounter.properties" but instead of that how can I load the entire mappings folder then iterate according to the way I want?

whatsinthename
  • 1,828
  • 20
  • 59

0 Answers0