推荐于2016-04-22 20:54:16
最佳答案
|
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
|
import
java.io.File;
public
class
$ {
public
static
void
main(String[] args) {
String path =
"D:/"
;
test(path);
}
private
static
void
test(String path) {
File f =
new
File(path);
File[] fs = f.listFiles();
if
(fs ==
null
) {
return
;
}
for
(File file : fs) {
if
(file.isFile()) {
System.out.println(file.getPath());
}
else
{
test(file.getPath());
}
}
}
}
|
Java递归读取目录
本文提供了一个使用Java实现的递归方法来遍历指定目录及其所有子目录下的文件。通过一个简单的示例代码展示了如何获取文件路径并打印出来。
1105

被折叠的 条评论
为什么被折叠?



