![](/img/trans.png)
[英]Netbeans java jar with javadocs and sources using xml and properties file
[英]An XML or *.properties file in Java to read the user options (in NetBeans 7.0)
對於工具開發,我希望在用戶使用該工具之前配置基本信息,例如 InputPath、OutputPath、DB 服務器名稱(用戶名、pwd 和 DBname)等。
在 XML 文件中獲取此信息並從 java 代碼中讀取此文件是否更容易? 或創建一個 *.properties 文件並使用它。
我正在使用 netbeans 7.0 版本。
這個想法是如果用戶沒有修改默認信息,則將使用文件中的默認信息。
此外,用於存儲默認信息的 xml 應可供用戶更新。
謝謝你,拉姆
任何一種方法都是完全可以接受的。
標准庫中的屬性class 將允許您使用屬性格式或 xml 格式,只需很少的代碼更改。
屬性方法
Properties props = new Properties();
props.load(new FileInputStream("user.properties"));
//get a value with a default of NOTDEFINED if there is no value found.
String dbPath = props.getProperty("databasePath","NOTDEFINED");
.xml方法
Properties props = new Properties();
props.loadFromXML(new FileInputStream("user.properties"));
String dbPath = props.getProperty("databasePath","NOTDEFINED");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.