Example one, find Java type file
Packagefile;ImportJava.io.File; Public classJava { Public Static intnum = 0; Public Static voidMain (string[] args) {//TODO auto-generated Method StubFile File =NewFile ("F:\\crt"); Show (file); System.out.println ("+num+" with "Jar file"); } Public Static voidShow (file file) {//TODO auto-generated Method Stub for(File f:file.listfiles ()) {if(F.isfile ()) {if(F.getname (). EndsWith (". dll") ) {num++; } }Else{show (f); } } }}
Example two, find various types of documents and number
Packageday05;ImportJava.io.File;ImportJava.util.HashMap;ImportJava.util.Map;//programming implementation statistics in a directory, how many kinds of files, respectively, the list is displayed Public classWork04 { Public Staticmap<string,integer> map =NewHashmap<string,integer>(); Public Static voidMain (string[] args) {//TODO auto-generated Method StubShowNewFile ("D:/QQQ")); Map.foreach ((k,v)-{System.out.printf ("%s=%d\n", k,v); }); } Public Static voidShow (File dir) {if(Dir.isdirectory ()) {file[] fs=Dir.listfiles (); for(File f:fs) {if(F.isdirectory ()) {Show (f); }Else if(F.isfile ()) {String n=F.getname (); intpos = N.lastindexof (".")); String ext= pos = =-1? "Unknown file": n.substring (pos+1); if(Map.containskey (EXT)) {map.put (ext, map.get (EXT) )+ 1); }Else{map.put (ext,1); } } } } }}
The number of files under the Java Lookup folder.