ResourceBundle class contain locale-specific objects,its easy way to storing and access key/value .
Properties file in java used to store application related configuration details .
Properties file contains pair of strings (key=value),
here is example for properties file
propertiesfile.properties
product_url=http://localhost:8080
adminname=rohan
with this example you retrieve the key values
import java.util.ResourceBundle;
public class Resourcebundle {
/**
* @author Rohan Kamat
*/
private static ResourceBundle services = null;
public String getServiceUrl(String service) {
String value = null;
String filepath="D:\\";
try {
if (services == null) {
services = ResourceBundle.getBundle(filepath+"properties.propertiesfile");
}
value =services.getString(service);
} catch (Exception exception) {
exception.printStackTrace();
}
return value;
}
public static void main(String args[]){
Resourcebundle resource=new Resourcebundle();
resource.getServiceUrl("adminname");
}
}
It was a great help.
ReplyDeletethanks manjesh
ReplyDelete