Following example demonstratres how to traverse a directory with the help of dir.isDirectory() and dir.list() methods of File class.
import java.io.File; public class Main { public static void main(String[] argv) throws Exception { System.out.println("The Directory is traversed."); visitAllDirsAndFiles(C://Java); } public static void visitAllDirsAndFiles(File dir) { System.out.println(dir); if (dir.isDirectory()) { String[] children = dir.list(); for (int i = 0; i < children.length; i++) { visitAllDirsAndFiles(new File(dir, children[i])); } } } }
The above code sample will produce the following result.
The Directory is traversed.
java_directories.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4