1 package test; 2 /* 3 * 打印 指定目录下和子目录下的的所有.java文件的路径. 4 * */ 5 import java.io.*; 6 import java.util.*; 7 8 public class Test14 9 { 10 public static void main(String[] args) 11 { 12 File dir = new File("C:\\Users\\Dell\\Workspaces\\MyEclipse 10"); 13 List<File> list = new ArrayList<File>(); 14 FileFilter filefilter = new FileFilter() 15 { 16 public boolean accept(File pathname) 17 { 18 if (pathname.getName().endsWith(".java")) 19 return true; 20 if (pathname.isDirectory()) 21 return true; 22 else 23 return false; 24 } 25 }; 26 method(dir.listFiles(filefilter), list, filefilter); 27 for (File file : list) 28 System.out.println(file); 29 } 30 public static void method(File[] files, List<File> list, FileFilter filefilter) 31 { 32 for (File f : files) 33 { 34 if (f.isDirectory()) 35 method(f.listFiles(filefilter), list, filefilter); 36 else 37 list.add(f); 38 } 39 } 40 }
时间: 2024-12-17 21:24:00