This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

Opening & Saving Problem

Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JFrame with 2 buttons namely button1 & button2. The primary role of button1 & button2 is to open-up a dailog to open & save documents.
1.) button1 should open the file and append it to my JTextArea.
2.) button2 should save everything on my JTextArea.
Before they can do this, I need to pass my 2 methods which are openFile() and openSave() to my button1 & button2 Action Listner.
My problem is that I cant seem to open and save files on my JTextArea. Can anyone pls, look if I forgot something or there is an error. If you may can you tweak my codes so that I can do opening & saving on my documents.
Thank you . . .
Here's the process >>>
button1.ActionListner {
button2.ActionListner {
Here's my codes :
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what I can make out from the code you placed in your post you don't actually do anything with the InputStream and OutputStreams which you create. This means that although you get a handle on the data you want you don't actually access it in any useful sense.
What you need to do is to tell your InputStream "input" to read in wahtever data is contained within the file and then place that data into your JTextArea.
The opposite goes for your save dialog, you need to output the data contained within your JTextArea and write it to the file, the details of which has already been returned by your JFileChooser object. Although I can't actually see a FileOutputStream created anywhere with which to save the file to disk.
For your "Open" button (Assuming the data is saved as a JTextArea object):

Now for your "Save" button:

I'm possibly missing something with only having a small code sample, it would be much better if I could have a copy of the whole class.
Hope this helps!
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
    Bookmark Topic Watch Topic
  • New Topic