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);
                    }
                }
            }
        }
    }
  • 相关阅读:
    (转载)Linux进程基础
    C语言字符串
    DNS域名解析服务
    Linux-SSH远程管理
    Linux文件系统深入了解
    Linux进程和计划任务管理
    Linux账户与权限管理
    MySQL实现读写分离
    SQL数据库常用函数
    MySQL进阶查询(二)
  • 原文地址:https://www.cnblogs.com/actioning/p/4402070.html
Copyright © 2011-2022 走看看