To access resource bundle in bean
public String getTextProp(){
String bundle_name= "com.gppsuite.view.ViewControllerBundle";
ResourceBundle resourceBundle = BundleFactory.getBundle(bundle_name);
String txt =null;
if(resourceBundle != null)
{
txt = resourceBundle.getString("string_id");
}
return txt;
}
Thanks Lakshman for your comments.
Including your comments in the post for the benefit of others.
2)
We can also use
java.util.ResourceBundle rb = ResourceBundle.getBundle("com/oracle/,,,,/Bundle1");
String txt = rb.getString("prop1");
3)
public String readPropertiesFile(String property){
String configureURL = null;
try{
InputStream is = ConfigureBean.class.getResourceAsStream("Engenio.properties");
Properties prop = new Properties();
prop.load(is);
configureURL = prop.getProperty(property);
is.close();
/* code to use values read from the file*/
}catch(Exception e){
e.printStackTrace();
}
return configureURL;
}
We can also use
ReplyDeletejava.util.ResourceBundle rb = ResourceBundle.getBundle("com/oracle/,,,,/Bundle1");
String txt = rb.getString("prop1");
Use can also try this
ReplyDeletepublic String readPropertiesFile(String property){
String configureURL = null;
try{
InputStream is = ConfigureBean.class.getResourceAsStream("Engenio.properties");
Properties prop = new Properties();
prop.load(is);
configureURL = prop.getProperty(property);
is.close();
/* code to use values read from the file*/
}catch(Exception e){
e.printStackTrace();
}
return configureURL;
}
The second method is actually the same as your first one. Except that first one is better since the second one has a greater chance of failing and throwing null pointers exceptions.
ReplyDeleteif the properties file "name.preperties" is directly under src folder, the method ResourceBundle resourceBundle = BundleFactory.getBundle("name") is not working, why ?
ReplyDeleteThanks for your post.
ReplyDeleteQuick question:
Is there a best practice when handling null properties (i.e., if you are using the .properties file inputs as text in a UI application, and setting the text from the properties on the server-side)?
Just curious.
It was so nice article and useful to Informatica learners. we also provide oracle ADF course online training our Cubtraining is leader in providing Software Training
ReplyDeletewonderful information, I had come to know about your blog from my friend nandu , hyderaba.
ReplyDeletei have read atleast 7 posts of yours by now, and let me tell you, your website gives the
best and the most interesting information. This is just the kind of information that i had
been looking for, i'm already your rss reader now and i would regularly watch out for the new posts.
Oracle fusion HCM Online Training
Oracle Fusion HCM Training
Thank you For Sharing Information
ReplyDeleteYaaron Studios is one of the rapidly growing editing studios in Hyderabad. We are the best Video Editing services in Hyderabad. We provides best graphic works like logo reveals, corporate presentation Etc. And also we gives the best Outdoor/Indoor shoots and Ad Making services.
Best video editing services in Hyderabad,ameerpet
Best Graphic Designing services in Hyderabad,ameerpet
Best Ad Making services in Hyderabad,ameerpet