Hi
We often have the requirement of reading properties from a file placed in external location of server . This always helps to make the changes in application with out down time.
Say , If you have configured a property named "PROMOAVAILABLE" in property files and is set to ON if promotion is applicable and OFF if not applicable.
Based on this you can alter your logic in the code and there will be no re deployments necessary.
code to read property file :
FileInputStream fileInputStream= null;
try {
File file=new File("/opt/oracle/read.properties"); // Property file location
fileInputStream= new FileInputStream(file);
ResourceBundle resource = new PropertyResourceBundle(fileInputStream);
String promo=resource.getString("PROMOAVAILABLE") ;
if("ON".equalsIgnoreCase(promo)){
//write code
}
else{
//write code
}
}catch (Exception e) {
logErrorStackTrace(e);
}finally{
try{
if (fileInputStream !=null) {
fileInputStream.close();
}
}catch (Exception e) {
logErrorStackTrace(e);
}
}
*Must close the FileInputStream after usage
We often have the requirement of reading properties from a file placed in external location of server . This always helps to make the changes in application with out down time.
Say , If you have configured a property named "PROMOAVAILABLE" in property files and is set to ON if promotion is applicable and OFF if not applicable.
Based on this you can alter your logic in the code and there will be no re deployments necessary.
code to read property file :
FileInputStream fileInputStream= null;
try {
File file=new File("/opt/oracle/read.properties"); // Property file location
fileInputStream= new FileInputStream(file);
ResourceBundle resource = new PropertyResourceBundle(fileInputStream);
String promo=resource.getString("PROMOAVAILABLE") ;
if("ON".equalsIgnoreCase(promo)){
//write code
}
else{
//write code
}
}catch (Exception e) {
logErrorStackTrace(e);
}finally{
try{
if (fileInputStream !=null) {
fileInputStream.close();
}
}catch (Exception e) {
logErrorStackTrace(e);
}
}
*Must close the FileInputStream after usage
No comments:
Post a Comment