| | |
Saving a file
![]() |
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
I have a text area and a button on a frame and there's some text in the text area. What i need is when the user clicks the button whatever the text in the text area is saved to the file "C:\ret" with the aid of the file selector dialog.
I am only using awt components and not any swing components.
Can someone show me or e-mail me a sample program or sample codings or part of the sample program on how this can be done.
My e-mail is freesoft_2000@yahoo.com
I really hope someone can help me.
Thank you
Yours Sincerely
Richard West
I am only using awt components and not any swing components.
Can someone show me or e-mail me a sample program or sample codings or part of the sample program on how this can be done.
My e-mail is freesoft_2000@yahoo.com
I really hope someone can help me.
Thank you
Yours Sincerely
Richard West
first save the text in the text area in the string ...
String s = textArea.getText();
then make a file object
File f = new File("c\ret");
then make a writer object
FileWriter fw = new FileWriter(f);
then write into the file
fw.write(s);
This is a raw concept of writing into the file... sequential writing. Post more for any problems in you code.
String s = textArea.getText();
then make a file object
File f = new File("c\ret");
then make a writer object
FileWriter fw = new FileWriter(f);
then write into the file
fw.write(s);
This is a raw concept of writing into the file... sequential writing. Post more for any problems in you code.
•
•
Join Date: Jun 2004
Posts: 609
Reputation:
Solved Threads: 7
Hi everyone,
I am having a little problem with streams. When i declare the file and filewriter objects outside any functions i get the error saying that the exception must be caught but when i use the try and catch statements outside any functions i get an illegal function. Any way here is my code and i hope some sone can show me the right way of catching the exception outside any function declarations.
Here is my code
import java.io.*;
public class Streams implements ActionListener, WindowListener
{
//What i need is a way to catch the exceptions outside
//any function declarations
File inputFile = new File("C:/Haha.txt");
FileWriter fw = new FileWriter(inputFile);
BufferedWriter bw = new BufferedWriter(fw);
public static void main(String args[])throws IOException
{
Streams a = new Streams();
a.initialize();
}
}
Thank You
Yours Sincerely
Richard West
I am having a little problem with streams. When i declare the file and filewriter objects outside any functions i get the error saying that the exception must be caught but when i use the try and catch statements outside any functions i get an illegal function. Any way here is my code and i hope some sone can show me the right way of catching the exception outside any function declarations.
Here is my code
import java.io.*;
public class Streams implements ActionListener, WindowListener
{
//What i need is a way to catch the exceptions outside
//any function declarations
File inputFile = new File("C:/Haha.txt");
FileWriter fw = new FileWriter(inputFile);
BufferedWriter bw = new BufferedWriter(fw);
public static void main(String args[])throws IOException
{
Streams a = new Streams();
a.initialize();
}
}
Thank You
Yours Sincerely
Richard West
•
•
•
•
Originally Posted by freesoft_2000
File inputFile = new File("C:/Haha.txt");
FileWriter fw;
BufferedWriter bw;
![]() |
Similar Threads
- saving a file to database (C#)
- Saving excel sheet with few column names present as file name (Visual Basic 4 / 5 / 6)
- Photoshop file saving problem (Graphics and Multimedia)
- Photoshop file saving problem (Windows Software)
- Saving input data to a .txt file (Python)
- While I am Downloading ,One Dialogbox will open.When user will be saving file name... (ASP.NET)
- Saving a file using C++ (C++)
Other Threads in the Java Forum
- Previous Thread: fr.dyade.aaa.jndi.Naming ContextFactory
- Next Thread: matching regular expressions
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






