This Blog gives important code snippets in java. Will try to simplify the concepts as much as I can.
Thursday, December 1, 2011
Reading Property Files in java
Load property files via static blocks and retrieve them file those block when ever you want to read a property. This way we don't have to open file stream when we want to read a property.
private static Properties prop = null;
static{
java.io.InputStream inst = MyClass.class.getClassLoader().getResourceAsStream("com/../../Resources/PropFile.properties");
prop=new Properties();
try {
prop.load(inst);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//Retrieving value of a key
prop.getProperty("Key")
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment