Following code traverses a directory.

Java Code:
public class TraverseDirectory {

    private static void processDir(File dir) {

        System.out.print( (dir.isDirectory() ? "[D] : " : "[F] : "));
        System.out.println(dir);

    }

    private static void traverse(File dir) {

        processDir(dir);

        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (int i=0; i<children.length; i++) {
                traverse(new File(dir, children[i]));
            }
        }

    }

    public static void main(String[] args) {
        traverse(new File("new_dir"));
    }

}