import java.io.File;
public class ListFileName {
public static void list(File dir,StringBuilder str ) {
File[] files = dir.listFiles();
for(File file:files) {
if(file.isHidden()) {
continue;
}
if(file.isDirectory()) {
System.out.println(str + "目录" + file.getName());
str.append("*");
list(file,str);
}
else {
System.out.println(str + file.getName());
}
}
if(str.length() > 0)
str.deleteCharAt(0); //按字符算
}
public static void main(String[] args) {
StringBuilder str = new StringBuilder();
list(new File("F:\\黑马\\张孝祥_Java多线程与并发库高级应用"),str);
}
} |
|