Jerry Jacob's Blog

Passing Arguments to .property file

Posted in Java/ J2EE by jerlinworld on February 24, 2010

Property File Sample

app.welcome= Welcome {0} and {1}.
app.bye=Bye {0} and {1}.

Jave Code using MessageFormat


String propText=resBundle.getString("app.welcome");
java.text.MessageFormat msgFormatter = new java.text.MessageFormat(propText);

// Write the dynamic args you want to replace 
Object[] messageArguments = {"Jerry","Jacob"};  
 
String finalText= msgFormatter.format(messageArguments);