How to get all filenames of certain file types in a folder?
Hey!
I have built a small program that opens a csv-file and extracts some data from it. The user specify what file to be used by writing the file name in the prompt. How could I change my small program to automatically go over all files in a certain folder, instead of just one file at a time?
Thank you in advance
Found some code, but got another problem
I found a code that could do what I want, and it does it very good. But I am puzzled over one thing. I have some log files in a folder. All logs that are named 20081001 to 20081031 works great. But if I use files that are not named like this, I get an error saying the file is not present and cannot be open. Any suggestions?
Code:
List<String> filnamn = new ArrayList();
File folder = new File("c:/Log");
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
filnamn.add(listOfFiles[i].getName());
System.out.println(listOfFiles[i].getName());
}
}
for (int i = 0; i <= filnamn.size() - 1; i++) {
String teststr = filnamn.get(0);
CSVReader csvread = new CSVReader(new FileReader(teststr));
List<String[]> test = csvread.readAll();
Filter testfilter = new Filter(test);
}