Compsci 100, Fall 2009, Directory Recursion

These questions refer to the FileSizer class partiall reproduced below:

public class FileSizer { // static decl for FileChooser removed public static long THRESHOLD = 1000000L; // one million bytes public static void findBig(File dir, String tab) { File[] dirContents = dir.listFiles(); System.out.println(tab+"**:"+dir.getPath()); for(File f : dirContents){ if (f.isDirectory()) { findBig(f,tab+"\t"); } else { if (f.length() > THRESHOLD){ System.out.printf("%s%s%8d\n", tab, f.getName(), f.length()); } } } } public static void main(String[] args){ int action = ourOpenChooser.showOpenDialog(null); if (action == JFileChooser.APPROVE_OPTION){ File f = ourOpenChooser.getSelectedFile(); findBig(f,""); } System.exit(0); } }
  1. 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.
    
    
    
    
  2. 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.
    
    
    
  3. What steps are needed to use the MVC model from KWIC or 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?