PackageCom.sxd.createDao;ImportJava.io.File;ImportJava.time.LocalDateTime;ImportJava.util.HashMap;ImportJava.util.Map;ImportJava.util.TreeMap; Public classTest {Private LongA = 0; Map<string, file> map =NewHashmap<string, file>(); Map<string, string> repeatmap =NewTreemap<string,string>(); @org. Junit.test Public voidTest () {System.out.println (Localdatetime.now ()); //all files on the native diskFile [] files =file.listroots (); for(file file:files) {num (file); }//num (New File ("D:/baiduyundownload")); //under a single folderSystem.out.println ("Total number of computer files:" +a); System.out.println (Localdatetime.now ()); if(Repeatmap.size () > 0) {Repeatmap.foreach (k,v)->system.out.println ("File path:" +k+ "file name:" +v)); } } //calculate the total number of files in a folder Public voidnum (file file) {if(File.isdirectory ()) {file [] files=File.listfiles (); if(Files! =NULL){ for(File string:files) {num (string); } } }Else{a++; if(Map.containskey (File.getname ())) {file Thisfile=Map.get (File.getname ()); if(File.gettotalspace () = =Thisfile.gettotalspace ()) {Repeatmap.put (File.getpath (), File.getname ()); Repeatmap.put (Thisfile.getpath (), Thisfile.getname ()); } }Else{map.put (File.getname (), file); } } }}
"Java" recursively counts all files on local disk, extracts duplicate files, JDK8 map iterations