I was trying to read sub-directories(names of directories) of a directory in my class path resources using Spring Boot with snippet given below.
public List<File> getSubdirectories() { File file = ResourceUtils.getFile("classpath:/database/scripts"); return Arrays.stream(file.listFiles()).filter(File::isDirectory).map(File::getFileName) .collect(Collectors.toList()); } Now this would work well when we run this code from IDE. But when we build this app as a jar and runs it from there it throws a FileNotFoundException.
I tried to load the directory as class path resource as well. But didn't find any luck.
I'm currently using Java 8. So most of the Java 7 solutions won't work I guess. Is there any other way I can resolve this issue?