Below code, i am manually write "a.json", "b.json". But i want to get all file names in resources directory and is it possible?
public static void loadFiles() throws IOException {
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
List<String> fileNames = List.of("a.json", "b.json"); // Bad
// List<String> fileNames = getFileNamesInResources(); // Good
for (int i = 0; i < fileNames.size(); i++) {
String fileName = fileNames.get(i);
InputStream is = classLoader.getResourceAsStream(fileName);
String content = new String(is.readAllBytes(), StandardCharsets.UTF_8);
System.out.println(content);
is.close();
}
}