ResourceBundle bundle = ResourceBundle.getBundle("com.example.myapp.resources.MyResources"); String welcomeMsg = bundle.getString("welcome.message"); System.out.println(welcomeMsg);
ResourceBundle bundle = ResourceBundle.getBundle("com.example.myapp.resources.MyResources", new Locale("es", "MX")); String greeting = bundle.getString("greeting"); System.out.println(greeting);In this example, we're again getting a ResourceBundle instance for "MyResources.properties", but this time we're passing a Locale object with language "es" and country "MX" as the second argument to getBundle(). This will cause the bundle to search for localized versions of the resource file, such as "MyResources_es.properties" and "MyResources_es_MX.properties". We're then retrieving a string value mapped to the key "greeting". The ResourceBundle class is part of the java.util package.