What is the best way for parsing multiple files from multiple directories?
I have a folder that contains 51 sub folders and each sub folder contains 100 files.
I know how to scan one single file using
File dataFile = new File("A.txt");
scan = new Scanner (dataFile);
while (scan.hasNext()){
System.out.print(scan.next() + "\t");
}
but how to generalize this to read from the different directories ?
java.io.Fileto represent the primary input, this would allow you to useFile#listFilesto list the contents of your directory and pass each match to a method. You could also look at Walking the File Tree and use it to process your files. Depending your needs, you might even consider using some kind ofExecutorServiceto allow you to process multiple files simultaneously