File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Saving and opening an application ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Saving and opening an application ?" Watch "Saving and opening an application ?" New topic

Saving and opening an application ?

Avin Sinanan
Ranch Hand

Joined: Nov 07, 2001
Posts: 109
Hello my question is about saving and opening files.
I am creating a user interface application (not an applet ) using Java Swing. My GUI allows teh user to add various buttons to the JPanel and also move the buttons around. The user can also conenct lines to the Buttons and still move the buttons around while the line changes to suit.
I would like to know how does one save a particular configuration heor she has made on teh screen so later he or she can back and open the file and continue.
I know how to make the Open and Save boxes appear.. but they are just for show.. they do nothing. How does one create there own extensions for there own program. For example microsoft word uses .doc . Suppose you want your extension to be .zzz how do you do this.
Ok thanks for reading.. I know you all are busy but any help would be apreciated.. thanks a million... yours respectfully Avin Sinanan

yours respectfully<br />Avin Sinanan
Its Just Me

Joined: Jan 10, 2002
Posts: 21
You can name the files anything you want. For saving objects (not text, that is done differently but the same basics apply), just use a FileOutputStream and put it in an ObjectOutputStream. You can specify the filename and the extension (ie "hello.zzz") like this:
output = new ObjectOutputStream(new FileOutputStream("hello.zzz"));
You can save your object like this:
(Of course you can write multiple objects to the same file by repeating the above)
After you're done saving, you have to close the file, like this:
Remember: everything you want to save, has to be serializable. A lot of standard objects (such as String) are, but when you create your own objects and want to save these, they have to implement Serializable (don't forget to import*;!)
Opening and reading from files is done the same way:
input = new ObjectInputStream(new FileInputStream("hello.zzz"));
MyObject myObject = (MyObject) input.readObject(); (don't forget to typecast here)

good luck.
[ February 17, 2002: Message edited by: Allard van Hooff ]
John Mill

Joined: Feb 12, 2002
Posts: 11
Hi Avin
I can't remember the name of the vocab right now but there is an xml standard for defining screen layouts. I ran into it a year or so ago but I'm afraid that you'll have to try a search engine to find it ;->
I agree. Here's the link:
subject: Saving and opening an application ?
It's not a secret anymore!