aspose file tools
The moose likes Swing / AWT / SWT / JFace and the fly likes saving text area to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "saving text area to a file" Watch "saving text area to a file" New topic
Author

saving text area to a file

Mukesh Jain
Greenhorn

Joined: Jan 17, 2001
Posts: 9
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
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
Renee Zhang
Ranch Hand

Joined: Sep 10, 2001
Posts: 72
This is what I want too. Thank you, netharam.
 
 
subject: saving text area to a file
 
Threads others viewed
Struts FormFile (parsing .csv files)
Seaching and Replacing text program
how many ways do two java program communicate?
how to replace text in a file
Suggest a best way to read, process and write text file to file system. Huge text file in few MBs
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com