欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Read .properties file

程序员文章站 2022-03-02 14:36:13
...
rules.properties :


rule1.id=callagent
rule1.name=Longest Waiting 1
rule1.type=custom
rule1.class=com.brekeke.ctiserver.acd.RuleCallAgent
rule1.description=Assign a call to an agent who has been waiting the longest.
rule1.param1.target=agent_id
rule1.param1.label=Timeout (sec)
rule1.param2.label=Queue size
rule1.param3.label=Next number
rule1.param4.label=Next number14

rule2.id=test
rule2.name=High Skill 1
rule2.type=custom
rule2.description=Find an agent who has the highest skill.
rule2.rule1.id=callagent
rule2.rule2.id=callagent
rule2.param1.target=rule1.param1
rule2.param1.label=Timeout (sec)
rule2.param2.target=rule2.param1
rule2.param2.label=Queue size
rule2.param3.label=Next number
rule2.param4.label=Next number24

ReadPro.java

public class ReadPro {

/**
* @author Bill Zhang
*/
public static void main(String[] args) {
File file = new File("src/pro/rules.properties");
if(file.exists()){
try {
FileInputStream fistream = new FileInputStream(file);
InputStream inStream = new BufferedInputStream(fistream);
Properties pro = new Properties();
try {
pro.load(inStream);
// System.out.println("=============Get Value By rule_id=====================");
// System.out.println(pro.get("rule1.id"));
System.out.println("===========================");
Enumeration<?> enu = pro.propertyNames();
while(enu.hasMoreElements()){
String key = enu.nextElement().toString().trim();
String[] strTemp = key.split("\\."); // "\\" is a convert symbol without it not work in the JDK 6.x
for(int i=0; i<strTemp.length; i++){
if(strTemp[i].equals("id"))
System.out.println(pro.get(key));
}
}
} catch (IOException e) {
System.out.println("+++++++++IOException++++++++");
e.printStackTrace();
}
} catch (FileNotFoundException e) {
System.out.println("++++++++FileNotFoundException+++++++++++");
e.printStackTrace();
}
}else{
System.out.println("File Not Found!");
}

}

}
相关标签: JDK