Search code examples
javawindowsencryptionsaveregistry

Methodology for saving field data between application sessions


I'm working on an application that requires I save a field between application uses, so that I can retrieve the data during the next use (ex. save username when logged in, retrieve it and pre-populate username field when application is next launched). I've looked around and found a couple ways to accomplish this goal, such as encryption & saving in a file on the local machine, and saving the value in the Windows registry. Are any of these methods better than others for accomplishing this goal? Any other suggestions?


Solution

  • You can store it using the Java Preferences API which will store a small amount of data in a system-specific way. On Windows, I believe it stores it in the registry, but on a Mac or on Linux it will be stored in a manner appropriate to those systems.

    The data is stored, for the current user, under a key that is specific to the package of your class plus a string of your choosing. See the Preferences API Overview for more details.