Issue
I need to read all files inside a folder. Here's my path c:/records/today/ and inside path there are two files data1.txt and data2.txt. After getting the files, I need to read and display it. I already did with the first file, I just don't know how to do both.
File file = ResourceUtils.getFile("c:/records/today/data1.txt");
String content = new String(Files.readAllBytes(file.toPath()));
System.out.println(content);
Solution
Also, you can use this to check child paths isFile or directory
Arrays.stream(ResourceUtils.getFile("c:/records/today/data1.txt").listFiles())
.filter(File::isFile)
.forEach(file -> {
try {
String content = new String(Files.readAllBytes(file.toPath()));
System.out.println(content);
} catch (IOException e) {
e.printStackTrace();
}
});
Answered By - S.Balaban