FileDocCategorySizeDatePackage
TextChooser.javaAPI DocExample1561Sun Mar 28 19:08:42 BST 1999None

TextChooser

public class TextChooser extends Object implements FilenameFilter

Fields Summary
Constructors Summary
Methods Summary
public booleanaccept(java.io.File dir, java.lang.String name)

 
    if (name.endsWith(".java")) return true;
    else if (name.endsWith(".jav")) return true;
    else if (name.endsWith(".html")) return true;
    else if (name.endsWith(".htm")) return true;
    else if (name.endsWith(".txt")) return true;
    else if (name.endsWith(".text")) return true;
    return false;
 
  
public static java.io.FilegetFile()

  
    // dummy Frame, never shown
    Frame parent = new Frame();
    FileDialog fd = new FileDialog(parent, "Please choose a file:", 
     FileDialog.LOAD);
    fd.setFilenameFilter(new TextChooser());
    fd.show();

    // program stops here until user selects a file or cancels
    
    String dir = fd.getDirectory();
    String file = fd.getFile();
    
    // clean up our windows, they won't be needed again
    parent.dispose();
    fd.dispose();
    
    if (dir == null || file == null) { // user cancelled the dialog
      return null;
    }
    return new File(dir, file);
    
  
public static voidmain(java.lang.String[] args)

  
    try {
      File f = getFile();
      if (f == null) return;
      FileInputStream fin = new FileInputStream(f);
      StreamCopier.copy(fin, System.out);
    }
    catch (IOException e) {
      System.err.println(e);
    }    
  
    // Work around annoying AWT non-daemon thread bug
    System.exit(0);