Java basic File and recursive exercises use a File filter to filter small files smaller than kb in a specified folder and print them in a hierarchical manner (including all subfolders ),
Package com. swift. kuozhan; import java. io. file; import java. io. fileFilter;/* use the File filter to filter and obtain and print small files smaller than kb in the specified folder (including files in all subfolders ). */Public class kuaozhan1 {public static void main (String [] args) {File dir = new File ("c:/"); if (! Dir. exists () {throw new RuntimeException ("this folder does not exist");} get200 (dir, 0);} private static void get200 (File dir, int length) {if (! Dir. exists () {throw new RuntimeException ("this folder has no access permission") ;}for (int I = 0; I <length; I ++) System. out. print ("\ t"); System. out. println (dir); File [] files = dir. listFiles (new FileFilter () {@ Override public boolean accept (File pathname) {if (pathname. isDirectory () return true; if (pathname. isHidden () return false; if (pathname. length ()/1024 <200) return true; return false ;}}); for (File file: files) {if (file. isDirectory () {get200 (file, length + 1);} else {for (int I = 0; I <length; I ++) System. out. print ("\ t"); System. out. println ("\ t" + file );}}}}