[英]unable to parse .conf file using java
<TF_INFO_START>
<TF_HOST>`TF_IN`
<TF_ID>`3219`
<TF_INFO_END>
<SF_INFO>
<SF_NAME>`JOHN`<IP>`10.110.12.12`<SF_PORT>`9101`
<END_SF_INFO>
<COMPONENT_START_TAG>
<COMPONENT_NAME>`AISMOD`<PATH>`AISPATH`<TYPE>`U`<M>`main`
<COMPONENT_END_TAG>
我想解析上面的test.conf文件並在日志文件中顯示每個參數。
Properties configFile = new Properties();
configFile.load(new FileInputStream("C:/Users/JOHN/Desktop/test.conf"));
String foo = configFile.getProperty("TF_HOST");
我無法獲取TF_HOST和其他參數的值。結果為空。
誰能幫我解析以上文件內容
將conf文件寫為key = value,然后使用ResourceBundle可以輕松讀取文件。 喜歡
ResourceBundle rb = ResourceBundle.getundle("com.demo.conf");//path for conf file in my case it is in com.demo package
String value = rb.getString(key);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.