• 遍历目录文件


    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;
        }
    
  • 相关阅读:
    JSONP(处理跨域问题)
    Bootstrap 按钮
    input file 图片上传展示重新上传
    Bootstrap 表单
    Bootstrap 表格
    Bootstrap 代码
    Bootstrap 排版 文本
    bootstrap 栅格calss
    Bootsrap 直接使用
    Bootstrap3和Bootsrap4的区别
  • 原文地址:https://www.cnblogs.com/yangqimo/p/7488567.html
Copyright © 2020-2023  润新知