Results 1 to 3 of 3
Thread: Filename Filter problem
- 06-12-2008, 12:44 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 4
- Rep Power
- 0
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
- 06-12-2008, 03:27 PM #2
You may design a class that extends FileFilter....2. A filter
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,
sukatoaLast edited by sukatoa; 06-12-2008 at 03:31 PM.
freedom exists in the world of ideas
- 06-14-2008, 02:43 AM #3
Try this
Java 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; } });Daniel @ [www.littletutorials.com]
Language is froth on the surface of thought
Similar Threads
-
how to display the picture when the filename is not in order
By norazanita in forum New To JavaReplies: 5Last Post: 06-06-2008, 09:31 AM -
web content filter or internet filter
By sundarjothi in forum Advanced JavaReplies: 3Last Post: 05-15-2008, 11:36 AM -
Reading a directory and getting the filename
By mrjunsy in forum Advanced JavaReplies: 1Last Post: 05-10-2008, 02:36 AM -
servlet Filter problem
By saint_jorjo in forum New To JavaReplies: 1Last Post: 03-13-2008, 12:05 PM -
Need a filter
By revathi17 in forum New To JavaReplies: 1Last Post: 08-08-2007, 07:37 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks