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!"
Paul Labis is a young software engineer who is passionate in programming. He is one of the co-founder of CDO-IT Group and an expert in web-based Java programming. He is a graduate of BS-Information Management in Ateneo de Cagayan-Xavier University and an experienced software engineer with focus on Java technologies.
0 Comments