PackageCom.swift.kuozhan;ImportJava.io.File;ImportJava.io.FileFilter;/*Use the file filter filter to get and print small files smaller than 200K under the specified folder (including files for all subfolders). */ Public classKuaozhan1 { Public Static voidMain (string[] args) {File dir=NewFile ("c:/"); if(!dir.exists ()) { Throw NewRuntimeException ("This folder does not exist"); } get200 (dir,0); } Private Static voidget200 (File dir,intlength) { if(!dir.exists ()) { Throw NewRuntimeException ("This folder does not have access rights"); } for(inti = 0; i < length; i++) System.out.print ("\ T"); System.out.println (dir); file[] Files= Dir.listfiles (NewFileFilter () {@Override Public BooleanAccept (File pathname) {if(Pathname.isdirectory ())return true; if(Pathname.ishidden ())return false; if(Pathname.length ()/1024x768 < 200) return true; return false; } }); for(File file:files) {if(File.isdirectory ()) {get200 (file, length+ 1); } Else { for(inti = 0; i < length; i++) System.out.print ("\ T"); System.out.println ("\ T" +file); } } }}
Java basic file and recursive exercises use the filter filters to get and print small files smaller than 200K under the specified folder to print hierarchically (including files for all subfolders)