Re: FilenameFilter woes
Charles wrote:
Can we see the code for FilenameFilter?
You can download the code from Sun, but it won't be much because it's an
interface. Better would be to read the Javadocs for it:
<http://java.sun.com/javase/6/docs/api/java/io/FilenameFilter.html>
How are files and directories represented in Java?
By whether File.isDirectory() returns true.
<http://java.sun.com/javase/6/docs/api/java/io/File.html#isDirectory()>
or contrariwise, whether isFile() does not.
<http://java.sun.com/javase/6/docs/api/java/io/File.html#isFile()>
Needless to say the File methods are pass-throughs for information from the
underlying OS.
To the OP: You are truly going to regret all those println() calls in a
FilenameFilter.accept() method. They obscure the logic, both at compile time
and run time, and will slow things down horribly. What you want is the
'assert' keyword.
A FilenameFilter is supposed to be rather lean, implementable as an anonymous
class. Sometimes it pays to write one into fullness, as you did, for the more
complex implementations, which perhaps this is. Even so, keep the sensibility
of a lean implementation when writing one in its own named class.
Given the kinds of tests you're performing, you might consider implementing a
FileFilter instead, in conjunction with the File.listFiles( FileFilter ) method.
--
Lew