How to Use ResourceBundle.getBundle to get Properties Value at Runtime in Java?

Last updated
App Shah
Crunchify » Java and J2EE Tutorials » How to Use ResourceBundle.getBundle to get Properties Value at Runtime in Java?

Crunchify ResourceBundle - load properties file Tutorial

Backing a ResourceBundle with Properties Files Tips.

Java is very dynamic programing language. With thousands of APIs available for us to use, we do have a freedom of choice.

Some time back I’ve written an article on How to Read Values in Java? java.util.Properties is very strong API to retrieve, update config properties values at runtime which I used in previously mentioned tutorial .

In this tutorial I’ll go over ResourceBundle.getBundle API for the same. Properties file is used to store project specific settings, i.e.

It’s very important to use properties file and you should use it most of the time if you need use some properties at multiple location which has dynamic value. Just update in file and it you will get updated value at all the location.

In this tutorial we will name our config file to

We are going to use public static final ResourceBundle getBundle(String baseName)

Above method gets a resource bundle using the specified base name, the default locale, and the caller's class loader. Calling this method is equivalent to calling getBundle(baseName, Locale.getDefault(), this.getClass().getClassLoader()).

Let’s get started:


Create file with below contents:

#Crunchify Properties


Put file under package, in the same package as your file

Package Structure - CrunchifyTutorial


Create file


import java.util.Enumeration;
import java.util.ResourceBundle;

 * @author

public class CrunchifyReadConfigUsingResourceBundle {
	public static void main(String[] args) {

		try {
			ResourceBundle crunchifyResourceBundle = ResourceBundle.getBundle("");
			Enumeration<String> crunchifyKeys = crunchifyResourceBundle.getKeys();
			while (crunchifyKeys.hasMoreElements()) {
				String crunchifyKey = crunchifyKeys.nextElement();
				String value = crunchifyResourceBundle.getString(crunchifyKey);
				System.out.println(crunchifyKey + ": " + value);

		} catch (Exception e) {
			System.out.println("Error retrieving properties file: " + e);


Run the program and checkout result.

ResourceBundle Result

If you have list of below questions then also this tutorial will help:

  • How do I read a properties file with a Resource Bundle?
  • How to load and use a resource bundle from a file resource in Java?
  • Java ResourceBundle Tutorial
  • resourcebundle java example crunchify
  • What is resourcebundle in java?
  • How to load resource bundle from classpath and in Eclipse?

Leave a Comment