setResourceBundle() method of a Logger class used to set a resource bundle on this logger.we have to pass resource bundle object as a parameter to this method.After setting resource bundle all messages will be logged using the given resource bundle for its specific locale.
public void setResourceBundle(ResourceBundle bundle)
Parameters: This method accepts one parameter bundle which represents resource bundle that this logger shall use.
Return value: This method returns nothing.
Exception: This method throws following Exceptions:
- NullPointerException – if the given bundle is null.
- IllegalArgumentException – if the given bundle doesn’t have a base name, or if this logger already has a resource bundle set but the given bundle has a different base name.
- SecurityException – if a security manager exists, this logger is not anonymous, and the caller does not have LoggingPermission(“control”).
Below programs illustrate the setResourceBundle() method:
For the above program, there is a properties file name resourceBundle.properties. we have to add this file alongside the class to execute the program.
The output printed on console of Eclipse is shown below-
For the above program, there is a properties file name myResource. we have to add this file alongside the class to execute the program.
output printed on console output is shown below-
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.