递归打印文件目录以及文件名称
import java
.io
.File
;
public class 文件递归
{
public static void main(String
[] args
) {
File file
= new File("./src");
prints("-",file
);
}
public static void prints(String str
, File file
){
if (file
.list()==null
){
System
.out
.println(str
+file
.getName());
}else {
File
[] files
= file
.listFiles();
System
.out
.println(str
+file
.getName());
for (int i
=0;i
< files
.length
;i
++){
prints(str
+"-",files
[i
]);
}
}
}
}
持续更新,一起变强
转载请注明原文地址:https://tech.qufami.com/read-19723.html