FileDocCategorySizeDatePackage
FileTyper.javaAPI DocExample1084Tue Feb 14 13:29:14 GMT 2006None

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.setVisible(true);
    
    // 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)

  
    InputStream in = null;
    try {
      File f = getFile();
      if (f == null) return;
      in = new FileInputStream(f);
      for (int c = in.read(); c != -1; c = in.read()) {
        System.out.write(c);
      }
    }
    finally {
      if (in != null) in.close();
    }
  
    // Work around annoying AWT non-daemon thread bug.
    System.exit(0);