public class searchFile2 {
public static void main(String args[]) {
File dirObject=new File("f:\\jin");
Filter1 filterObj1=new Filter1("app");
Filter2 filterObj2=new Filter("html");
System.out.println("*******************************");
String[] filesObj1=dirObject.list(filterObj1);
for(int i=0;i<filesObj1.length;i++)
{
File fileObject=new File(dirObject, filesObj1[i]);
if(fileObject.isFile())
{
System.out.println("app file: "+fileObject);
}
else
{
System.out.println("sub directory: "+fileObject);
}
}
String[] filesObj2=dirObject.list(filterObj2);
for(int i=0;i<filesObj2.length;i++)
{
File fileObject=new File(dirObject, fileObj2[i]);
if(fileObject.isFile)
{
System.out.println("htm file: "+fileObject);
}
else
{
System.out.println("sub directory: "+fileObject);
}
}
}
}
class Filter1 implements FilenameFilter {
String fileExent;
Filter1(String exentObj) {
fileExent=exentObj;
}
public boolean accept(File dir,String name) {
return name.endsWith("."+fileExent);
}
}
class Filter2 implements FilenameFilter {
String fileName;
Filter2(String fileName) {
this.fileName=fileName;
}
public boolean accept(File dir,String name) {
return name.startsWith(fileName+".");
}
}
救命..........