This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Saving/Opening a text file, from a text area. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Saving/Opening a text file, from a text area." Watch "Saving/Opening a text file, from a text area." New topic
Author

Saving/Opening a text file, from a text area.

Jayson Johnson
Greenhorn

Joined: Nov 14, 2009
Posts: 2
Hello, I am new to this site. I have posted a few times in devshed, I have also asked a similar question as I am now. Thanks to several over at devshed I have got a calculator program working and added a few things to it. My question is that, I added a textarea, and I want to be able to open simple text files, and save to a text file. I have done some googling and looked around at java.sun, but im still not sure which methods/classes I need to accomplish this. I have already coded the menus for save/open, but I dont know how to actually search for and OPEN a text or SAVE AS a text. If anyone can point me in the right direction it would be greatly appreciated. BTW, MyDevShedPost this is the post at devshed, complete with the code for my calculator. Thanks in advance.

-Jay
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 31054
    
162

Jayson,
Forgetting about your Swing interface for a minute, do you know how to write a program with a main method to read a file and output to the result to standard out? If so, you are most of the way there.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40029
    
  28
And welcome to JavaRanch
Jayson Johnson
Greenhorn

Joined: Nov 14, 2009
Posts: 2
No, not at all. Although I have been playing around with it and got it to open a text file, BUT it only displayed the first line, AND you had to type in the filename. BUT this is far from what I want to do, as I couldnt navigate through the file system and it only opened 1 line. I have since found that I need to be looking at FileReader and FileWriter. Basically what I need to do is understand what it actually does to save and open a file. What I mean does it just copy it straight in? Or does it have to convert it? Any information will help. As I find the java.sun is informative, but not user friendly. Its still somewhat Greek to me. Thanks.

-Jay
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18986
    
    8

Sounds like you need to use a JFileChooser to chose a file. It also sounds like you should read the Basic I/O tutorial to learn more about those things.
 
Don't get me started about those stupid light bulbs.
 
subject: Saving/Opening a text file, from a text area.