Java是否提供某种Register \"Cookies"来存储临时数据?

Vik*_*ehr 4 java registry cookies applet

Java是否提供了某种注册表或cookie机制,我可以存储小块数据以加载下一次启动我启动java应用程序或applet?

例如,应用程序设置,如上次打开的文件等

Bri*_*new 8

请参阅Java Preferences API.

它允许您存储每个用户每个系统的首选项.它会将首选项存储在Unix/Linux上的隐藏文件中,并在基于Windows的系统中使用注册表(尽管这取决于实现).

注意:我不确定它是否适用于applet(由于安全限制).


dfa*_*dfa 5

Java属性在内存中广泛用作持久性格式(文件).它们也得到IDE,ant,maven等工具的广泛支持.

Properties非常易于使用,它有几个有用的方法(存储,加载和存储):

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"));
Run Code Online (Sandbox Code Playgroud)

Java .properties文件如下所示:

# 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