コード例 #1
0
 private void readInFile(String fileName) {
   try {
     FileReader r = new FileReader(fileName);
     area.read(r, null);
     r.close();
     currentFile = fileName;
     setTitle(currentFile + " - CoreyTextEditor");
     changed = false;
   } catch (IOException e) {
     Toolkit.getDefaultToolkit().beep();
     JOptionPane.showMessageDialog(this, "Editor can't find the file called " + fileName);
   }
 }
コード例 #2
0
    // Query user for a filename and attempt to open and read the file into the
    // text component.
    public void actionPerformed(ActionEvent ev) {
      JFileChooser chooser = new JFileChooser();
      if (chooser.showOpenDialog(SimpleEditor.this) != JFileChooser.APPROVE_OPTION) return;
      File file = chooser.getSelectedFile();
      if (file == null) return;

      FileReader reader = null;
      try {
        reader = new FileReader(file);
        textComp.read(reader, null);
      } catch (IOException ex) {
        JOptionPane.showMessageDialog(
            SimpleEditor.this, "File Not Found", "ERROR", JOptionPane.ERROR_MESSAGE);
      } finally {
        if (reader != null) {
          try {
            reader.close();
          } catch (IOException x) {
          }
        }
      }
    }