You can use the following code to implement your own file browser in Java. visitAllDirsAndFiles method traverses all directories and files in a given directory. visitAllDirsAndFiles method does the same only for directories. process() method should be defined by you based on your needs..

  // Process all files and directories under dir
    public static void visitAllDirsAndFiles(File dir) {

        // You can do whatever you want with this directory
        // E.g. printing its name to the console
        process(dir);
    
        if (dir.isDirectory()) {
            String[] children = dir.list();
            for (int i=0; i<children.length; i++) {
                visitAllDirsAndFiles(new File(dir, children[i]));
            }
        }
    }
    
    // Process only directories under dir
    public static void visitAllDirs(File dir) {
        if (dir.isDirectory()) {
      
            // You can do whatever you want with this directory
            // E.g. printing its name to the console
            process(dir);
    
            String[] children = dir.list();
            for (int i=0; i<children.length; i++) {
                visitAllDirs(new File(dir, children[i]));
            }
        }
    }