public static void getDirectory(String pathname) {
Path path = new File(pathname).toPath();
try {
DirectoryStream<Path> children = Files.newDirectoryStream(path);
if (children != null) {
for (Path child : children) {
// System.out.println("Dir==>"+child.toAbsolutePath());
File file = new File(child.toString());
if(file.isDirectory()){
System.out.println("是文件夹"+child.toString());
getSubFile(file);
}
if(file.isFile()){
System.out.println("是文件"+child.toString());
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static void getSubFile(File file) throws IOException {
DirectoryStream<Path> twoChildren = Files.newDirectoryStream(file.toPath());
if (twoChildren != null) {
for (Path twoChild : twoChildren) {
File fileTwo = new File(twoChild.toString());
if(fileTwo.isDirectory()){
System.out.println("是文件夹"+twoChild.toString());
getSubFile(fileTwo);
}
if(fileTwo.isFile()){
System.out.println("是文件"+twoChild.toString());
}
}
}
}
public static void main(String[] args) {
getDirectory("D:\\diaodutai");
}