怎么在GUI中,把从监听文本框获得的字符串,通过IO流写入一个文件中?
我尝试把数据写入的动作放在监听class里,但是总是抛出异常,请前辈们指教
谢谢

解决方案 »

  1.   

    下面是监听程序代码
    class BL1 implements ActionListener {
         public void actionPerformed(ActionEvent e) throws IOException {
        String s1="";
        String ss="";
        int i2=0,i3=0;
     try {
                     DataOutputStream out = 
                        new DataOutputStream(
                            new BufferedOutputStream (
                                new FileOutputStream("Data.csv")));
                     out.writeBytes("4,2,3");
                     out.close();
              }catch (EOFException x) {
                 System.err.println("xxxxxxx");
              }     
        }    
    }
    这下面是错误报告H:\java>javac MainFrame.java
    .\ChildFrame.java:35: ChildFrame.BL1 の actionPerformed(java.awt.event.ActionEve
    nt) は java.awt.event.ActionListener の actionPerformed(java.awt.event.ActionEve
    nt) を実装できません。オーバーライドされたメソッドは java.io.IOException をスロ
    ーしません。
                    public void actionPerformed(ActionEvent e) throws IOException {
                                ^
    エラー 1 個是什么问题啊
      

  2.   

    class BL1
        extends AbstractAction {
      public void actionPerformed(ActionEvent e) {
        String s1 = "";
        String ss = "";
        int i2 = 0, i3 = 0;
        try {
          DataOutputStream out =
              new DataOutputStream(
                  new BufferedOutputStream(
                      new FileOutputStream("Data.csv")));
          out.writeBytes("4,2,3");
          out.close();
        }
        catch (FileNotFoundException ex) {
          ex.printStackTrace();
        }
        catch (IOException ex) {
          ex.printStackTrace();
        }
      }
    }