一、传统的方法
File file=new File(".");
File[] subFile=file.listFiles();
for(File theFile:subFile){
if(theFile.getName().endsWith(".xls")){
theFile.delete();
}
}
二、通过FileFilter来实现
File file = new File(".");
File[] files = file.listFiles(new FileFilter()
{
@Override
public boolean accept(File pathname)
{
if (pathname.getName().endsWith(".xls"))
{
return true;
}
return false;
}
});
for (File tempfile : files)
{
tempfile.delete();
}