2013-04-30 97 views
1

我正在嘗試爲讀取和寫入隨機訪問文件中的信息並隨意顯示它的程序製作GUI。我不能操作GUI以外的任何東西,並且必須參考預先構建的方法(如果方法確實無法使用,那麼我可以例外)。動作偵聽器/拋出IOException衝突

我遇到的問題是寫入文件時處理IOException。

public static class EdtButtonHandler implements ActionListener 
    { 


     public void actionPerformed(ActionEvent e) 
     { 

      if (e.getActionCommand().equals("Confirm")) //if the confirm button is pressed 
      { 

        writeAll(); //runs all write methods using the strings from the text field 

       frameAddMovie.setVisible(false); 
      } 

的writeAll指的是一系列基於它傳遞的字符串寫入文件的方法,這些字符串都來自於我的GUI窗口的文本字段。他們都看起來像這樣;

public static void writeDirector(int recordNum, String directorIn)throws IOException 
    { 
     int position; 
     RandomAccessFile recordFile = new RandomAccessFile("RecordFile", "rw"); 
     position = recSize * (recordNum-1)+32; // read 32 spaces into the record to the start of the director line 
     recordFile.seek(position); 
     recordFile.writeBytes(directorIn); 

    } 

在確認按鈕被按下並且writeAll()運行的時候,拋出的IOException異常無法被方法或Class捕獲。

+0

你能給予充分的例外,比如'IOException異常文件未found'或任何其他? – 2013-04-30 16:41:26

回答

0
if (e.getActionCommand().equals("Confirm")) //if the confirm button is pressed 

你不希望出現這種情況是

if (e.getSource() = buttonname)