listFiles()
/* windows中删除一个文件夹,删除原理: 删除目录从里往外删,既然从里往外删,就需要用到递归。 */ import java.io.*; class DirectoryDemo { public static void main(String[] args) { File file = new File("E:\\开发视频\\毕向东Java"); printDirectory(file,0); } private static void printDirectory(File file , int level) { System.out.println(file); File [] files = file.listFiles(); level++; for(int i= 0;i<files.length;i++) { if(files[i].isDirectory()) printDirectory(files[0],level); else System.out.println(files[i]); } } }