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);
                    }
                }
            }
        }
    }
  • 相关阅读:
    接口和抽象类的区别联系(一)
    股指期货-基础知识
    A股魔咒
    .NET 分布式架构
    Spring Cloud Netflix
    现货、期货、期权、权证
    复盘-20190321
    复盘思考
    公司法
    2019年行情思考
  • 原文地址:https://www.cnblogs.com/actioning/p/4402070.html
Copyright © 2011-2022 走看看