Wednesday, May 26, 2010

How to traverse a directory structure in Java

the program will traverse the given directory and print out all the directories and files absolute path and name one by one.

public class DisplayDirectoryAndFile{
public static void main (String args[]) {
displayIt(new File("C:\\Downloads"));
public static void displayIt(File node){
String[] subNote = node.list();
for(String filename : subNote){
displayIt(new File(node, filename));

No comments:

Post a Comment