import java.io.File;
import java.io.IOException;
public class t13 {
public static void main(String[] args) throws IOException {
listFile("D://abc");
}
private static void listFile(String path) throws IOException {
if (path == null) {
return ;
}
File[] files = new File(path).listFiles();
if (files == null) {
return ;
}
for (File file : files) {
if (file.isFile()) {
System.out.println("文件的路径为: " + file.getCanonicalPath() + "文件的名称为 :" + file.getName());
}else if (file.isDirectory()) {
listFile(file.getPath());
System.out.println("文件夹的路径为: " + file.getCanonicalPath() + "文件夹的名称为 :" + file.getName());
}else {
System.out.println("遍历出错");
}
}
}
}