如题 求助 文件过滤器FilenameFilter
------最佳解决方案--------------------------------------------------------
public class Filter implements FilenameFilter {
private String suffix;
public Filter(String suffix) {
super();
this.suffix = suffix;
}
@Override
public boolean accept(File dir, String filename) {
// TODO Auto-generated method stub
return filename.endsWith(suffix);
}
}
public class FindFileUtil {
private static String targetPath = "D:\\pro";
public String targetFile(){
File file = new File(targetPath);
File[] filelist = file.listFiles(new Filter(".java"));
for(int i = 0;i<filelist.length;){
return filelist[i].getName();
}
return null;
}
}
------其他解决方案--------------------------------------------------------
读文件之后,能取到一个文件对象吧。比如叫file,file.getName()就能拿到名字了。再判断endWith("后缀");就行了