How to scan a folder in Java?

前端 未结 7 1566
死守一世寂寞
死守一世寂寞 2020-11-27 16:03

How can I get list all the files within a folder recursively in Java?

相关标签:
7条回答
  • 2020-11-27 16:45
    public static void directory(File dir) {
        File[] files = dir.listFiles();
        for (File file : files) {
            System.out.println(file.getAbsolutePath());
            if (file.listFiles() != null)
                directory(file);        
        }
    } 
    

    Here dir is Directory to be scanned. e.g. c:\

    0 讨论(0)
提交回复
热议问题