- 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;
- }
- //该片段来自于http://www.codesnippet.cn/detail/0408201410112.html
来源: http://www.codesnippet.cn/detail/0408201410112.html