Java是否提供某种类型的注册表或cookie机制,我可以存储小块数据以加载下一次启动我启动一个java应用程序或applet?Java是否提供某种Register “Cookies”来存储临时数据?
例如如上次程序设置打开的文件等
Java是否提供某种类型的注册表或cookie机制,我可以存储小块数据以加载下一次启动我启动一个java应用程序或applet?Java是否提供某种Register “Cookies”来存储临时数据?
例如如上次程序设置打开的文件等
Java属性被广泛用作内存中的持久性格式(文件)。他们还广泛地被像IDE,蚂蚁,行家等工具支持
类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"));
一个Java属性文件看起来像:
# 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
它允许您存储首选项每个用户和每个系统。它将在Unix/Linux的隐藏文件中存储首选项,并在基于Windows的系统中使用注册表(尽管这取决于实现)。
注意:我不确定它是否适用于小程序(由于安全限制)。
这同样适用于Mac OS的Unix操作系统下的假设? – 2009-08-11 09:46:49
我会这样想的 – 2009-08-11 09:50:19