Read Properties File in Java With ResourceBundle

There are a number of ways to load and read properties file from Java, but the easiest and most straightforward is using the ResourceBundle class.

First, you need to create a properties file under resources folder. In a typical Maven project, this looks like the following

java resourcebundle properties file

 In this example, the properties file is called

The content of the properties file is in the format of name=value



In a Java class, we can use the ResourceBundle class to read from the properties file:

public class ReadPropertiesFile {

    private static ResourceBundle rb = ResourceBundle.getBundle("config");

    public static void main(String[] args) {
        String browser = rb.getString("browser");