import java.util.MissingResourceException;
import java.util.ResourceBundle;
public class Messages {
private static final String BUNDLE_NAME = "com.xxx.cs.mm.service.messages"; //messages.properties文件和Messages类在同一个包下,包名:com.xxx.cs.mm.service
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
private Messages() {
}
public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}
====
@Test
public void test02() throws IOException{
Properties prop = new Properties();
// InputStream in = Object.class.getResourceAsStream("/test/test.properties");
InputStream in = ClassLoader.getSystemResourceAsStream("test/test.properties");
prop.load(in);
String name = prop.getProperty("test.name");
System.out.println("02name:"+name);
}
import java.util.ResourceBundle;
public class Messages {
private static final String BUNDLE_NAME = "com.xxx.cs.mm.service.messages"; //messages.properties文件和Messages类在同一个包下,包名:com.xxx.cs.mm.service
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
private Messages() {
}
public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return '!' + key + '!';
}
}
}
====
@Test
public void test02() throws IOException{
Properties prop = new Properties();
// InputStream in = Object.class.getResourceAsStream("/test/test.properties");
InputStream in = ClassLoader.getSystemResourceAsStream("test/test.properties");
prop.load(in);
String name = prop.getProperty("test.name");
System.out.println("02name:"+name);
}