递归方法
用到了File类的exist,isFile,listFiles,getPath,getName
1 public static void findall(File file ) { 2 if(!file.exists())System.out.print("文件不存在!"); 3 if(file.isFile()) { 4 System.out.println(file.getPath()+" "+file.getName()); 5 }else { 6 File[] files=file.listFiles(); 7 if(files.length==0) { 8 System.out.println("no file"); 9 }else { 10 for(File f:files) { 11 findall(f); 12 } 13 } 14 } 15 } 16 public static void main(String[] args) throws IOException { 17 findall(new File("E://PYTHON"));//(叛徒! 18 }
原文:https://www.cnblogs.com/zhangmora/p/12657194.html