Java递归地获得一个目录下的文件总数

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

 
public static  int getTotalOfFiles(String path)
    {
        int total = 0;
        int sum=0;
        File tmpF = new File(path);
        File[] files = tmpF.listFiles();
        if(files ==null )
            total = 0;
        else{
            for(int i=0; i < files.length; i++)
            {
                if(files[i].isFile())
                    total++;
                else if(files[i].isDirectory())
                    sum = getTotalOfFiles(files[i].getAbsolutePath());
            }
            total += sum;
        }
        return total;
  
    }