Red wine
Red wine

Reputation: 172

Saving / loading user preferences to file

I have used Delphi for more than 10 years, and am now interested in using Eclipse and Java. With Delphi, I have developed code whereby with any application, regardless of how many forms, text boxes, checkboxes and other means of setting user preferences, I can save and load the defaults with one line of code to save and one to load in any new application I develop.

With a Java gui, I have managed to programmatically gather a list of all the user interface gui components, but have not managed to use ObjectInputStream to load the settings saved with ObjectOutputStream. There are two problems (so far!):

  1. ObjectInputStream.ReadObject() needs typecasting to the class being loaded. Is there a way to do this when the class is not known until runtime?
  2. ObjectInputStream.ReadObject() appears to produce a new instance of an oject, and I do not know how to read the data into the existing components (JTextField(s) etc).

Yes, I'll admit I am a newbie! Thanks for any help.

Upvotes: 2

Views: 290

Answers (1)

Waleed Almadanat
Waleed Almadanat

Reputation: 1037

I would highly recommend you check Java Preferences or simply the java Properties class which is simpler.

Upvotes: 1

Related Questions