- public class Test11{
- public static void main(String[] args){
- File file = new File("D:\\java");//关联文件路径;
- String[] files = file.list(new FilenameFilter()
- {//复写accept方法,
- public boolean accept(File dir,String name){
- return name.endsWith(".java");//返回name.endsWith("要过滤的文件名");
- }
- });
- for(String s :files){
- System.out.println(s);
- }
- }
- }
复制代码 |