Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 在 Java 中递归列出文件
我认为 File[] files = folder.listFiles() 只能列出第一级文件。有没有办法递归列出文件?
不是内置的,但您可以编写一个简短的递归程序来递归遍历目录树。
void listAll(File dir, List<File> res) { for (File f : dir.listFiles()) { if (f.isDirectory()) { listAll(f, res); } else { res.add(f); } } }