Use Arguments on Property File
The goal on this tutorial is to be able to format a value on a properties file given its parameter or arguments. It is best describe as passing value as a parameter and inserting those values on the string retrieved from the properties file.
To better understand what I'm doing, read and understand my example code below.
Property File Sample
message.welcome= Welcome {0} to {1}!
message.thank= Thank you for you visit {0}.
ResourceBundle resBundle = new ResourceBundle("path to property file");
String welcomeText=resBundle.getString("message.welcome");
MessageFormat msgFormatter = new MessageFormat(welcomeText);
// Create the dynamic args you want to replace
Object[] messageArguments = {"Techie boy","Philippines"};
String finalText= msgFormatter.format(messageArguments);
The finalText will result to "Welcome Techie boy to Philippines!"
0 Comments