屬性文件中的一些嘗試後和大量的谷歌-ING最後我問再次=)的XPage - 保存從JavaBean的
我有一個Java Bean,創建一個包含一些用戶對我的數據庫與工作TreeSet<String>
的。因爲創建我的TreeSet
需要一些時間,所以我想將它保存到properties
文件中。
在我的Bean中獲取/讀取屬性文件沒有問題,同時設置屬性很簡單,但是如何創建一個OutputStream
到我的資源?
代碼片段:
try {
Properties userproperties;
userproperties = new Properties();
userproperties.load(FacesContextEx.getCurrentInstance().getExternalContext().getResourceAsStream("WEB-INF/user.properties"));
for (String groupmember : groupmembers) {
userproperties.setProperty("UserList", groupmember);
}
// userproperties.save(OutputStream, comments)
} catch (Exception e) {
// some errorhandling
}
你有沒有嘗試過使用「user.properties」或'getRealPath()'這種方式獲得'OutputStream'? http://www.coderanch.com/t/358508/Servlets/java/write-Property-file-Run-time –