The Artima Developer Community
Sponsored Link

Java Answers Forum
Saving files

7 replies on 1 page. Most recent reply: May 19, 2004 10:31 AM by Cory

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 7 replies on 1 page
Cory

Posts: 5
Nickname: g3n0c1d3
Registered: May, 2004

Saving files Posted: May 12, 2004 9:30 AM
Reply to this message Reply
Advertisement
How would you make a simple button that will take info from textfields and save it to a file?


Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: Saving files Posted: May 12, 2004 2:43 PM
Reply to this message Reply
Have your class with the button implement ActionListener. When the actionPerformed method is invoked by the button click .. capture the text from your textfields and call your method to write those values to a file.

Regards,
Ray

Cory

Posts: 5
Nickname: g3n0c1d3
Registered: May, 2004

Re: Saving files Posted: May 17, 2004 9:57 AM
Reply to this message Reply
Do you have a sample code I could see because I am learning to program right now and I only have about 9 months of experience in programming.

Cory

Posts: 5
Nickname: g3n0c1d3
Registered: May, 2004

Re: Saving files Posted: May 17, 2004 10:13 AM
Reply to this message Reply
When ever I save it will delete what was already in the file but I want it to add it to what is already in the file. So would I just append the textfield inputs or something like that?

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: Saving files Posted: May 17, 2004 3:47 PM
Reply to this message Reply
When you create the object of FileOutputStream then pass true as its second argument. That way it won't overwrite the existing contents, rather it will append it. YOu can create file output stream as

FileOutputStream fos = new FileOutputStream (your_file_object, true);

Jeroen Wenting

Posts: 88
Nickname: jwenting
Registered: Mar, 2004

Re: Saving files Posted: May 17, 2004 11:44 PM
Reply to this message Reply
> Do you have a sample code I could see because I am
> learning to program right now and I only have about 9
> months of experience in programming.

Get a decent book on Java and Swing. This is so basic just about any tutorial will have the parts, it's only a matter of taking the pieces and putting them together.

button->actionlistener->filestream->file

Daniel Ray

Posts: 53
Nickname: budoray
Registered: Oct, 2002

Re: Saving files Posted: May 18, 2004 2:39 PM
Reply to this message Reply
Here's an example that uses a JFileChooser.

http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html.

Post what your code if you still need help.

Cory

Posts: 5
Nickname: g3n0c1d3
Registered: May, 2004

Re: Saving files Posted: May 19, 2004 10:31 AM
Reply to this message Reply
i appectiate all of your help I have it working now thank you.

Flat View: This topic has 7 replies on 1 page
Topic: how to create exe file using java? Previous Topic   Next Topic Topic: Creating a JFrame from a *Modal* JDialog

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use