Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save application setting in java & javafx

Tags:

java

save

javafx

I'm very new to this topic and trying to gain some understanding. I'm writing an application that allows user to personalize it and create his/own preferences, such as font color, size, certain nodes' positions and etc. While doing my research, I found couple examples using xml files to store users' perferenace.

Is this the best way to store information? Is there a more secure way to do it? since xml file is readable for people and not just the machine.

like image 359
George Wang Avatar asked Apr 08 '18 18:04

George Wang


1 Answers

If you need to save more user informations, you can use a database.
But if you need to save one user information, you can use Preferences :

Preferences pref;
pref = Preferences.userNodeForPackage(yourClass.class);
pref.put("yourPreferenceName","yourPreferenceValue");
//This create a String preference if it not exists or modify the value if 
//exists

Preferences pref;
pref = Preferences.userNodeForPackage(yourClass.class); 
String preference = pref.get("yourPreferenceName","yourPreferenceValue");
//This give you the value of the preference

If you want to know more about the preferences go here.

like image 165
Gabriel Avatar answered Nov 19 '22 21:11

Gabriel