import java.io.*; import java.util.*; public class ManageContent { private int dir_deep=0; private int dir_size = 0; private int sourcepath_deep; //输入路径相对于根目录的深度 private Hashtable ht=new Hashtable(); //储存输入路径下的所有子目录,及其相对于根目录的深度keys=(String)dirPath,values=(Integer)dirDeep public synchronized int getSize(String dir_path) throws FileNotFoundException { File dir = new File(dir_path); if (!dir.exists()) { throw new FileNotFoundException(); } if (!dir.isDirectory()) { dir_size = (int) dir.length(); } else { File[] fe = dir.listFiles(); for (int i = 0; i < fe.length; i++) { if (fe[i].isDirectory()) { getSize(fe[i].toString()); } else { dir_size += fe[i].length(); } } } return dir_size; } |