| shyam_oec |
16Feb2008 11:11 |
how FilenameFilter works?
With reference to the code below can u tell me when and how accept() method of FilenameFilter is called,and from where parameter of accept() method are passed?
In a nutshell i mean to say how FilenameFilter works?
Code:
import java.io.*;
pubic class OnlyExt implements FilenameFilter
{
String str;
public OnlyExt(String str)
{
this.str="."+str;
}
public boolean accept(File dir,String name)
{
return name.endsWith(str);
}
}
class DirListOnly
{
public static void main(String [] args)
{
String dirname="/java";
File f1=new File(dirname);
FilenameFilter only=new OnlyExt("html");
String s[]=f1.list(only);
for(int i=0;i<s.length;i++)
{
System.out.println(s[i]);
}
}
}
|