我有一个Spring Boot v2.1.2.RELEASE应用程序。 我有这个文件夹../ src / main / resources / icons / svg / white /
我正在尝试列出该文件夹的所有文件,但似乎该文件夹不存在
@SpringBootApplication
public class SvgManagerApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(SvgManagerApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
try {
File folder = new File("icons/svg/white/");
listFilesForFolder(folder);
} catch (IOException ex) {
System.out.println(ex.getMessage());
}
}
public void listFilesForFolder(final File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
System.out.println(fileEntry.getName());
}
}
}
}
答案 0 :(得分:2)
File folder= ResourceUtils.getFile("classpath:icons/svg/white/");