-
Filename Filter problem
Hi there..
I recently discovered the File class and how useful it is when searching for files in a certain directory..
Now, I want to pass 2 string parameters;
1. Directory name
2. A filter
The passing of the 2 strings will be in a constructor..
Is there any way that I'm able to search in a directory for a filter corresponding to the string "E.*\.htm"..the reason for doing this is so that I can put .htm files starting with "E" into an array by themselves
-
You may design a class that extends FileFilter....
And override the two methods getDescription() and accept()
All filtering operations should be done on overriden accept(File) method....
You may browse the FileFilter class in src file(zip) that can be found inside jdk folder....(just in case you are curious about its implementation)
Hope that helps,
sukatoa
-
Try this
Code:
File dir = new File("E:\");
File[] files = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return name.startsWith("*.htm") ? true : false;
}
});