Saturday, January 15, 2011

How to use resource bundle?


Generally to avoid hard codings in program we use a file called properties file.. This file can contain labels,sql queries,array sizes.. etc.So whenever there is a change in requirement without touching the source code we can change these values… It is also used for internationalization

This is the way to declare a resource bundle:
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle("resources.myApplication");
here resources.myApplication is the property file name

This is the syntax to get a value from that file:
stringName = RESOURCE_BUNDLE.getString("getStringName");

No comments:

Post a Comment

Please Give Your Comments!!!