File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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

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

Jayson Johnson

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.

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33129

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
And welcome to JavaRanch
Jayson Johnson

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.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

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.
I agree. Here's the link:
subject: Saving/Opening a text file, from a text area.
It's not a secret anymore!