Compsci 100e, Fall 2009, Directory Recursion

These questions refer to the FindBigFiles class partially reproduced below:

public class FindBigFiles
{
    protected static JFileChooser ourOpenChooser = new JFileChooser(System
            .getProperties().getProperty("user.dir"));
    static { // static initialization block - why needed?
        ourOpenChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    }
    public static long THRESHOLD = 1000000L; // one million bytes
    
    public static void printBig(File dir, String tab)
    {
        File[] dirContents = dir.listFiles();
        System.out.println(tab+"**:"+dir.getPath());
        for(File f : dirContents){
            if (f.isDirectory()) {
                // TODO: complete printBig for directory
              
            } 
            else {
                // TODO: complete printBig for files
            }
            
        }
    }
     public static void main(String[] args)
    {
        String input = JOptionPane.showInputDialog("Enter minimum file size:", Long.toString(THRESHOLD));
        
        THRESHOLD = Long.parseLong(input);
    int action = ourOpenChooser.showOpenDialog(null);
    if (action == JFileChooser.APPROVE_OPTION){
        File f = ourOpenChooser.getSelectedFile();
        printBig(f,"");
    }
    System.exit(0);

    }

}

  1. Modify printBig to handle the two different kinds of Files: directories and normal files.
    
    
    
    
  2. Modify the code to print all big files first, then the subdirectories (if there are any). In other words, all files are printed first, then all subdirectories are processed recursively.
    
    
    
    
  3. Currently the name of a directory is printed then all the big files in that directory are printed. Suppose you don't want to print a directory name unless some file in the directory is big/exceeds the threshold. But you still want to print the directory name first and then the files exceeding the limit after that. How would you modify the code to do this.
    
    
    
  4. What steps are needed to use the MVC model from Markov and a GUI interface to process big files. In other words, if you want to move the big-file-finding code into the GUI architecture we use in the course what do you do?