Sir Can you please tell me how to save the data or text of a TextArea to a file It's urgent please Mukesh
netharam ram
Ranch Hand
Joined: Aug 09, 2001
Posts: 202
posted
0
This is can be done using streams.Use FileOutputStream to open a file and write the content of the TextArea to that file. *************** code: ****************** import java.io.*; import java.awt.*; import java.awt.event.*; public class TArea_File extends Frame implements ActionListener { Button b; TextArea t; public TArea_File() { setSize(200,200); setVisible(true); t=new TextArea("",10,30); b=new Button("save_To_File"); setLayout(new FlowLayout()); add(t); add(b); b.addActionListener(this); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { System.exit(0); } }); }//end of constructor public void actionPerformed(ActionEvent ae) { try { String s=t.getText(); if(s.length()>0) { FileDialog fd= new FileDialog(this,"Save File As",FileDialog.SAVE); fd.setFile("temp.txt"); fd.setDirectory("c:\\windows\\temp"); fd.setVisible(true); String path=fd.getDirectory()+fd.getFile();
FileOutputStream fos=new FileOutputStream(path); System.out.println(s); byte[] b=s.getBytes(); fos.write(b); fos.close(); } }catch(Exception e){System.out.println(e);} } public static void main(String args[]) { new TArea_File(); } } *************** end of code ****************** Good Luck. Netharam