Below is a snippet of a java program. I would like to know the output
and the reason for the same which is printed at the end. If there does
exist a problem, then what is the problem and its solution? If there is
no problem, good, we are going the right way.. :-) [PJ]
//router.properties
ProcessCreditOrder=firstDest
avm:ProcessValuation=secondDest
//Tester.java
public class Tester {
/**
* @param args
*/
public static void main(String[] args) {
Properties properties = new Properties();
try {
//No Problem, router.properties was found
properties.load(Tester.class.getClassLoader().getResourceAsStream("route
r.properties"));
System.out.println(properties.getProperty("ProcessCreditOrder"));
System.out.println(properties.getProperty("avm:ProcessValuation"));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
1 comments:
Output:
firstDest
null
Concept:
The name value pairs in the java properties file can be of formats:
a. name=value (This all us know definitely know)
b. name:value
c. name value
So, if you put properties.list(System.out)
You will see
ProcessCreditOrder=firstDest
avm=ProcessValuation=secondDest
Solution:
The solution is to escape the special characters. The escape character
for property files is ‘\’.
As in, in property files put:
ProcessCreditOrder=firstDest
avm\:ProcessValuation=secondDest
Post a Comment