java递归统计一个文件夹含子文件夹里文件不同后缀的出现次数
生活随笔
收集整理的這篇文章主要介紹了
java递归统计一个文件夹含子文件夹里文件不同后缀的出现次数
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
/*** 統(tǒng)計一個文件夾中不同文件出現(xiàn)的次數(shù)*/
public class demo1 {public static void main(String[] args) {File file = new File("IoFile");HashMap<String, Integer> mp = new HashMap<>();getCount(mp, file);System.out.println(mp);}private static void getCount(HashMap<String, Integer> mp, File file) {File[] files = file.listFiles();for (File f : files) {if (f.isFile()) {String name = f.getName();String[] split = name.split("\\.");if (split.length == 2){String filename = split[1];if (mp.containsKey(filename)){Integer count =mp.get(filename);count++;mp.put(filename,count);}else{//不存在這個后綴的文件mp.put(filename,1);}}} else {getCount(mp, f);}}}
}
總結
以上是生活随笔為你收集整理的java递归统计一个文件夹含子文件夹里文件不同后缀的出现次数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 1.74英寸超大屏手表!华为Watch
- 下一篇: linux子系统停止运行,linux 系