获取.properties文件
程序员文章站
2022-04-01 22:07:23
...
在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; } } }