public class FileRecursive { public static void main(String[] args) { File file=new File("D:/"); testFile(file); } public static void testFile(File file){ if (file.isDirectory()) { for (File f : file.listFiles()) { testFile(f); } }else{ System.out.println(file.getName()); } } }