遍历获得文件夹下的所有文件

 

 

 

public void traverseFolder2(String path) {

        File file = new File(path);
        if (file.exists()) {
            File[] files = file.listFiles();
            if (null == files || files.length == 0) {
                System.out.println("文件夹是空的!");
                return;
            } else {
                for (File file2 : files) {
                    if (file2.isDirectory()) {
                        System.out.println("文件夹:" + file2.getAbsolutePath());
                        traverseFolder2(file2.getAbsolutePath());
                    } else {
                        String absolutePath = file2.getAbsolutePath();
                        System.out.println("文件:" + absolutePath);
                        int index = absolutePath.lastIndexOf(".");
                     if(index != -1){
                 String suffix = absolutePath.substring(index);
                 if (".xlsx".equals(suffix.toLowerCase()) || ".xls".equals(suffix.toLowerCase())) {

                 }
              }
 } } } } else { System.out.println("文件不存在!"); } } 

 



posted @ 2021-01-26 17:41  我没有出家  阅读(98)  评论(0编辑  收藏  举报