复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33public class Test1 { public static void main(String[] args) { //例D:qrcodeFile文件夹下包含20190116和20190117俩个文件夹, //20190116和20190117俩个文件夹中分别有俩个文件 isDirectory(new File("D://qrcodeFile")); } public static void isDirectory(File file) { if(file.exists()){ if (file.isFile()) { System.out.println("file is ==>>" + file.getAbsolutePath()); /* 输出结果 * file is ==>>D:qrcodeFile201901165c594aee7a3d4b99b234b21456d053c4.png * file is ==>>D:qrcodeFile2019011695db451237344c51b4d797ddd9a71dce.png * file is ==>>D:qrcodeFile201901175c594aee7a3d4b99b0c9b21456d053c4.png * file is ==>>D:qrcodeFile2019011795db457467344c51b4d797ddd9a71dce.png * */ }else{ File[] list = file.listFiles();//list获取的结果:[D:qrcodeFile20190116, D:qrcodeFile20190117] if (list.length == 0) { System.out.println(file.getAbsolutePath() + " is null"); } else { for (int i = 0; i < list.length; i++) { isDirectory(list[i]); } } } }else{ System.out.println("文件不存在!"); } } }
最后
以上就是烂漫小蚂蚁最近收集整理的关于遍历目标文件夹下所有的文件的全部内容,更多相关遍历目标文件夹下所有内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复