在classes文件夹下放MPI.properties文件,下面方式可取得配置内容
public class MPIProperties {
private static final String BUNDLE_NAME = "MPI";
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
.getBundle(BUNDLE_NAME);
private MPIProperties() {
}
/**
* 从MPI属性文件中取得键的值
*
* @param key
* 键
* @return 值
*/
public static String getString(String key) {
try {
return RESOURCE_BUNDLE.getString(key);
} catch (MissingResourceException e) {
return key;
}
}
}
本文介绍了一种在Java中通过ResourceBundle类从特定的属性文件(MPI.properties)读取配置信息的方法。该方法允许应用程序轻松地从classes文件夹下的MPI.properties文件中检索所需的键值。

被折叠的 条评论
为什么被折叠?



