用RANDOMACCESSFILE吧~ 自己去查查HELP~

解决方案 »

  1.   

    4)读文件  FileReader       以行为单位读
     BufferedReader in;
     FileReader file; 
    try
     {File f=new File ("F:\\my_bag\\vj_file\\读文件\\","target.htm");
     file=new FileReader(f);
     in=new BufferedReader (file);
     }
     catch(FileNotFoundException e){}
    -----------------
    public void actionPerformed(ActionEvent e)
    {String s;
    if(e.getSource ()==button)
    try
    {while((s=in.readLine ())!=null)
     text.append (s+'\n');
     }
    catch(IOException exp){}
    }
    }
    ///////////////////////////////////////////////////
    5)写文件  FileWriter          以行为单位写
     BufferedWriter out;
     FileWriter tofile;
     try
      {tofile=new FileWriter ("write_in_here.txt");
       out=new BufferedWriter  (tofile);
      }
      catch(FileNotFoundException e){}
      catch(IOException e){}
      addWindowListener (new WindowAdapter()
    {public void windowClosing(WindowEvent e)
    {setVisible (false);
    System.exit (0);}
    });  
     
     }
     public void actionPerformed(ActionEvent e)
    {String s;
    if(e.getSource ()==button_me)
    try
    {out.write(text.getText (),0,(text.getText()).length ());
     out.flush ();
     }
    catch(IOException exp){text.setText ("have problem.");}
    }
    }