Recursively find all text files in directory

前端 未结 3 606
离开以前
离开以前 2020-12-10 21:31

I am trying to get the names of all of the text files in a directory. If the directory has subdirectories then I also want to get any text files in those as well. I am not s

3条回答
  •  时光说笑
    2020-12-10 22:18

    This is a recursive problem

    public void find_files(File root)
    {
        File[] files = root.listFiles(); 
        for (File file : files) {
            if (file.isFile()) {
                ...
            } else if (file.isDirectory()) {
                find_files(file);
            }
        }
    }
    

提交回复
热议问题