B
Bill Medland
I am just working through an example in Bruce Eckel's "Thinking in
Java" (3rd Edn), looking at his first Directory Listing example. I
don't see why his FilenameFilter is as complex as it is and so I assume
that there is something I am not understanding about FilenameFilter.
Unfortunately the 1.4.2 documentation isn't any clearer. Can someone
explain what the danger is that Bruce is avoiding?
Bruce's DirFilter has the following accept method;
public boolean accept (File dir, String name) {
// Strip path information, search for regex:
return pattern.matcher(
new File(name).getName()).matches();
}
Why is it not simply return pattern.matcher(name).matches?
The comment seems to suggest that 'name' might be a full path but I see
that it isn't when I run it on my machine.
The 1.4.2 documentation seems to suggest that 'name' is the actual file
name within 'dir'
So when would new File(name).getName() not be name?
Or is it just bulletproofing the code?
Java" (3rd Edn), looking at his first Directory Listing example. I
don't see why his FilenameFilter is as complex as it is and so I assume
that there is something I am not understanding about FilenameFilter.
Unfortunately the 1.4.2 documentation isn't any clearer. Can someone
explain what the danger is that Bruce is avoiding?
Bruce's DirFilter has the following accept method;
public boolean accept (File dir, String name) {
// Strip path information, search for regex:
return pattern.matcher(
new File(name).getName()).matches();
}
Why is it not simply return pattern.matcher(name).matches?
The comment seems to suggest that 'name' might be a full path but I see
that it isn't when I run it on my machine.
The 1.4.2 documentation seems to suggest that 'name' is the actual file
name within 'dir'
So when would new File(name).getName() not be name?
Or is it just bulletproofing the code?