简体   繁体   中英

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.

我强烈建议您检查Java偏好设置,或者只检查更简单的java 属性类。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM