zoukankan      html  css  js  c++  java
  • 遍历目录文件

    public static List<String> listFile(List<String> lstFileNames, File f,
                String suffix, boolean isdepth) {
            // 若是目录, 采用递归的方法遍历子目录
            try {
                if (f.isDirectory()) {
                    File[] t = f.listFiles();
                    for (int i = 0; i < t.length; i++) {
                        if (isdepth || t[i].isFile()) {
                            listFile(lstFileNames, t[i], suffix, isdepth);
                        }
                    }
                } else {
                    String filePath = f.getPath();
                    if (!suffix.equals("")) {
                        int begIndex = filePath.lastIndexOf("."); 
                        String tempsuffix = "";
    
                        if (begIndex != -1) {
                            tempsuffix = filePath.substring(begIndex + 1,
                                    filePath.length());
                            if (suffix.contains("." + tempsuffix + ".")) {
                                System.out.println("filePath:"+filePath);
                                lstFileNames.add(filePath);
                            }
                        }
                    } else {
                        lstFileNames.add(filePath);
                    }
                }
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
    
            return lstFileNames;
        }
    
  • 相关阅读:
    2019年第二周作业
    2019年pta作业第二题——求最大值及其下标
    2019春第十一周作业
    2019春第十周作业
    2019年寒假作业3
    2019年寒假作业2
    2019年寒假作业1
    我的老师
    自说
    Day16
  • 原文地址:https://www.cnblogs.com/yangqimo/p/7488567.html
Copyright © 2011-2022 走看看