package demo01;
import java.io.File;
public class Demo02 {
public static void main(String[] args) {
findFiles("输入要遍历的目录");
}
public static void findFiles(String path) {
if (path == null) {
return;
}
File f = new File(path);
File[] files = f.listFiles();
if (files == null) {
return;
}
for (File file : files) {
if (file.isFile()) {
System.out.println(file.getName());
}else if(file.isDirectory()){
findFiles(file.getPath());
}else {
System.out.println("error");
}
}
}
}
|
|