1
I need to store some information of my application for when the user starts it again to be loaded the data of the last use. At first I thought about using the Windows registry (in this case I’m sure the application will only run in Win environment), then I looked for how to do and found the class Preferences
.
I have a Hashmap with approximately 10 values (it may be that over time others appear) that represent the user’s preferences. The problem is that Preferences
does not allow storing a Map
, then I would have to go through it by inserting each String to 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 be an "ugly" thing on the record by the amount of Keys. No Map
, for me it’s normal but I don’t know how it will look in the reg system by never having worked with it before. And here comes my doubts:
Should I use the S.O. registry to store information of this type? For "this type," consider basic information for an application. If the answer is no, when then should I make use of the system record?
As stated before, new preferences may appear with the time. It is best to abandon the idea of saving to the registry and create a file (.txt) with preferences?
But as I said: The platform will be Windows and this is guaranteed. My doubts are at point 1 and 2 of the question.
– Renan Gomes
Despite the multiplatform, condorco with the use of databases and text files. + 1
– Caffé
I don’t see this amount of data in the windows registry as long as it is transparent to the user (it doesn’t have to manage these records). I believe that there are simpler and more robust solutions as demonstrated in the answer. The problem of using windows logs is that, back and forth, they create unexpected problems.
– EduardoFernandes
@Eduardofernandes thank you, helped a lot. I searched and found some disadvantages after reading your comment.
– Renan Gomes
Dear @rrnan, if the answer is correct for your question, please mark it by clicking on the "check" sign. Thank you.
– EduardoFernandes