User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 455,968 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,739 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 12395 | Replies: 3
Reply
Join Date: Jun 2004
Posts: 604
Reputation: freesoft_2000 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Help Saving a file

  #1  
Aug 24th, 2004
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2004
Location: Pakistan
Posts: 1,673
Reputation: nanosani is an unknown quantity at this point 
Rep Power: 8
Solved Threads: 50
Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: Saving a file

  #2  
Aug 25th, 2004
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.
Reply With Quote  
Join Date: Jun 2004
Posts: 604
Reputation: freesoft_2000 is an unknown quantity at this point 
Rep Power: 6
Solved Threads: 6
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: Saving a file

  #3  
Aug 25th, 2004
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
Reply With Quote  
Join Date: Jul 2004
Location: Pakistan
Posts: 1,673
Reputation: nanosani is an unknown quantity at this point 
Rep Power: 8
Solved Threads: 50
Colleague
nanosani's Avatar
nanosani nanosani is offline Offline
Unauthenticated Liar

Re: Saving a file

  #4  
Aug 26th, 2004
Originally Posted by freesoft_2000
File inputFile = new File("C:/Haha.txt");
FileWriter fw;
BufferedWriter bw;
Declare these outside the functions and then initialize them in your functions where you want to use them ... and make sure you have a try catch block where you put the file writer or file reader catching IOException for writer and FileNotFoundException for reader.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 9:10 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC