FileDocCategorySizeDatePackage
FileTyper.javaAPI DocExample1111Sun Mar 28 19:08:32 BST 1999None

FileTyper

public class FileTyper extends Object

Fields Summary
Constructors Summary
Methods Summary
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.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);