I need to store some information from my application so that when the user starts it again, the last use data will be loaded. At first I thought about using the Windows registry (in that case I'm sure the application will only run in the Win environment), I then looked for how to do it and found the class Preferences
.
I have a HashMap with approximately 10 values (others may appear over time) that represent user preferences. The problem is that Preferences
does not allow storing a Map
, so I would have to go through it by inserting each String to the preferences:
// Map de preferências
Map<String,String> prefsMap = new HashMap<>();
prefsMap.put("last_report", "10/10/1950");
prefsMap.put("last_dir", "C:\Users\UserName\");
prefsMap.put("splash", "false");
prefsMap.put("load_style", "true");
// outros 6 valores...
// Inserindo no Registro
Preferences prefs = Preferences.systemNodeForPackage(Main.class);
for(Map.Entry<String,String> each : prefsMap.entrySet())
prefs.put(each.getKey(), each.getValue());
Looking at this code, it looks like it's going to get a "ugly" thing on record by the amount of keys. In Map
, for me it is normal but I do not know how it will be in the reg system because I have never worked with it before. And here comes my doubts:
Should I use the S.O. registry to store such information? By "that kind," consider basic information about an application. If the answer is no, when should I make use of the system registry?
As mentioned before, new preferences may appear with the time. It is best to abandon the idea of saving in the registry and file (.txt) with preferences?