1 Packagetest;2 /*3 * Print the path of all. java files under the specified directory and sub-directories.4 * */5 ImportJava.io.*;6 ImportJava.util.*;7 8 Public classTest149 {Ten Public Static voidMain (string[] args) One { AFile dir =NewFile ("C:\\users\\dell\\workspaces\\myeclipse 10"); -list<file> list =NewArraylist<file>(); -FileFilter FileFilter =NewFileFilter () the { - Public BooleanAccept (File pathname) - { - if(Pathname.getname (). EndsWith (". Java")) + return true; - if(Pathname.isdirectory ()) + return true; A Else at return false; - } - }; - Method (Dir.listfiles (filefilter), list, filefilter); - for(File file:list) - System.out.println (file); in } - Public Static voidMethod (file[] files, list<file>list, FileFilter filefilter) to { + for(File f:files) - { the if(F.isdirectory ()) * Method (F.listfiles (filefilter), list, filefilter); $ ElsePanax Notoginseng List.add (f); - } the } +}
Prints the path of all. java files under the specified directory and subdirectories. (using FileFilter Filter)