zoukankan      html  css  js  c++  java
  • 文件类型检测

    import java.io.File;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map.Entry;
    
    public class FileListCollect {
    
        public static void main(String[] args) throws Exception {
    
            File root = new File("D:\01.Working Area\99.Srouce File\crm-sh-dev");
            HashMap<String, Integer> hm = new HashMap<String, Integer>();
    
            showAllFiles(root, hm);
    
            Iterator<Entry<String, Integer>> iter = hm.entrySet().iterator();
            while (iter.hasNext()) {
                Entry<String, Integer> entry = (Entry<String, Integer>) iter.next();
                System.out.println("suffix:   " + String.format("%1$-20s", entry.getKey()) + "    count:  " + entry.getValue());
            }
    
        }
    
        final static void showAllFiles(File dir, HashMap<String, Integer> hm) throws Exception {
            File[] fs = dir.listFiles();
            for (int i = 0; i < fs.length; i++) {
                System.out.println(fs[i].getAbsolutePath());
                if (fs[i].isDirectory()) {
                    try {
                        showAllFiles(fs[i], hm);
                    } catch (Exception e) {
    
                    }
                } else {
                    String fname = fs[i].getAbsolutePath();
                    String suffix = fname.substring(fname.lastIndexOf(".") + 1);
                    // System.out.println(suffix);
                    if (hm.containsKey(suffix)) {
                        int cut = hm.get(suffix).intValue();
                        hm.put(suffix, cut + 1);
                    } else {
                        hm.put(suffix, 1);
                    }
                }
            }
        }
    }
  • 相关阅读:
    C# extern关键字的用法
    C#自定义集合类(二)
    C#自定义集合类(一)
    LINQ中交集、并集、差集、去重(十四)
    LINQ中转换操作符(十三)
    Oracle实现连乘和求和
    适配器模式
    HTTP网络协议与手写Web服务容器
    代理模式
    设计模式的几条家规
  • 原文地址:https://www.cnblogs.com/actioning/p/4402070.html
Copyright © 2011-2022 走看看