Does Java provide some sort of Register\"Cookies" for storing of temporary data?

applet, cookies, java, registry

Solution

Java Properties are widely used both as persistence format (file) both in memory. They are also widely supported by tools like IDE, ant, maven, etc.

The class Properties is very simple to use and it has several useful method for your purpose (store, load and store):

Properties preferences = new Properties();
preferences.put("color", "red");
preferences.put("style", "bold");
preferences.store(new FileOutputStream("prefs.properties"), "preferences");

// reload the properties
Properties preferences = new Properties();
preferences.load(new FileInputStream("prefs.properties"));

A Java .properties file looks like:

# You are reading the ".properties" entry.
! The exclamation mark can also mark text as comments.
website = http://en.wikipedia.org/
language = English
# The backslash below tells the application to continue reading
# the value onto the next line.
message = Welcome to \
          Wikipedia!
# Add spaces to the key
key\ with\ spaces = This is the value that could be looked up with the key "key with spaces".
# Unicode
tab : \u0009  

Problem

Does the Java provide some sort of registry- or cookie mechanism where I can store small pieces of data to load next start I start an java application- or applet? For example the application settings such as last opened file etc

Original source