MessageLoader
package pkg;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;
import java.util.Properties;
public class MessageLoader {
static private String resource = "pkg/Message.properties";
static public String getMessage(String key, Object... args) {
InputStream is = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(resource);
Properties props = new Properties();
try {
props.load(is);
} catch (IOException e) {
return null;
}
String value = (String) props.get(key);
if (args.length != 0) {
value = MessageFormat.format(value, args);
}
return value;
}
public static void main(String args[]) {
{
String s = MessageLoader.getMessage("test");
System.out.println(s);
}
{
String s = MessageLoader.getMessage("test2", "aaa");
System.out.println(s);
}
}
}