I am trying to read files from a folder to java, I found this snippet and used it.
File folder = new File("Z..");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
File file = listOfFiles[i];
if (file.isFile() && file.getName().endsWith(".txt")) {
String content = FileUtils.readFileToString(file);
}
This works fine except it doesn't retrieve the files in order. I have files numbered file 0,file 1, file2.....file10 and how it retrieves it file 0 file 1 file 10 and then file 2, What should I to retrieve it in proper series. Should I be using something else? I'm new to this.