2011-04-14 92 views

回答

3

您可以使用自己的默認properties文件。你只需要幾行即可完成。

也有內置屬性,但是,這些並不簡單,但它們是標準的。

恕我直言大多數時間使用普通的Proeprties文件。

本教程中的示例。這是一個更復雜的例子,你可以只有一個屬性文件。

// create and load default properties 
Properties defaultProps = new Properties(); 
FileInputStream in = new FileInputStream("defaultProperties"); 
defaultProps.load(in); 
in.close(); 

// create application properties with default 
Properties applicationProps = new Properties(defaultProps); 

// now load properties from last invocation 
in = new FileInputStream("appProperties"); 
applicationProps.load(in); 
in.close(); 
+1

where defaultProperties located?另外,appProperties在哪裏? – user705414 2011-04-14 08:02:21

+0

字符串「defaultProperties」和「appProperties」是文件名。無論你放在哪裏,它們都是。 – 2011-04-14 08:24:27

0

你必須自己加載你的屬性文件或在命令行傳遞參數。

5

簡短的回答是否定的。

稍微長一點的答案從一個問題本身開始:應該由該文件配置什麼?

對於java的日誌記錄API(java.util.logging),存在一個標準屬性文件來配置它。其他框架也可以使用標準配置文件。但是這總是隻配置特定於這個框架的東西。

如果你想持久化配置,你可能想要使用Preference-API。這使您可以保存與用戶或JVM保持一致的配置數據。

0

有一個小型圖書館,您可以使用它自動爲您加載屬性:Confucius