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