i want to read multiple csv files from a folder in java. All files are csv and with same format, but problem is the path to the folder i get is like this only.
> conf/files
This is a folder where all my csv files are. I have a program which read single file when path is given like
> conf/files/sample.csv
If i could get a list of file name's like these i can read all those. Please help...
List<String> filenames = new LinkedList<String>();
public void listFilesForFolder(final File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
listFilesForFolder(fileEntry);
} else {
if(fileEntry.getName().contains(".csv"))
filenames.add(fileEntry.getName());
}
}
}
final File folder = new File("/home/you/Desktop");
listFilesForFolder(folder);
This way, only have to loop over the filenames list, and access how you already know
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With