没有废话只有代码,复制粘贴即可使用
package com.lfs;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
public class GetAllFile {
private static Map<String,Map<String,Long>> map = new HashMap();
public static void main(String[] args) {
File file = new File("F:");
findPath(file);
for(Map.Entry<String, Map<String, Long>> each : map.entrySet()){
Map<String, Long> temp = each.getValue();
String path = null;
Long mem = 0L;
for(Map.Entry<String,Long> m : temp.entrySet()){
path = m.getKey();
mem = m.getValue();
}
mem = mem / (1024*1024);
if(mem > 300)
System.out.println("\t大小:\t"+ mem + "MB"
+"\t\t\t\t文件名:\t"+ each.getKey() + "\t\t\t\t路径:\t"+ path);
}
}
public static void findPath(File f){
if(f != null){
File[] files = f.listFiles();
if(files != null){
for(File file : files) {
if (file.isFile()) {
Map<String, Long> temp = new HashMap();
temp.put(file.getAbsolutePath(), file.length());
map.put(file.getName(), temp);
} else {
if(file != null)
findPath(file);
}
}
}
}
return ;
}
}