|
package com.renxing.r0038_filefilter;
import java.io.File;
import java.io.FilenameFilter;
class MyFileNameFilter implements FilenameFilter
{
@Override
public boolean accept(File dir, String name)
{
System.out.println(dir+":::"+name);
return true;
}
}
public class FileNameFilterDemo
{
public static void bianli(File[] files)
{
for(int i=0;i<files.length;i++)
{
if(files.exists())
{
if(files.isDirectory())
{
System.out.println("files["+i+"]"+files.getName()+"是一个文件夹");
}
else
{
System.out.println("files["+i+"]"+files.getName()+"是一个文件");
}
}
}
}
public static void main(String[] args)
{
File file=new File("c://");
if(file.exists())
{
File[] strs=file.listFiles(new MyFileNameFilter());
bianli(strs);
}else
{
System.out.println("");
}
}
} |
|