public class LoadPropertiesByCode {
/**
* 通过key获取properties配置文件的value
* @param code
* @return value
*/
public static String getTextByCode(String code){
ResourceBundle bundle = ResourceBundle.getBundle("constants");
return bundle.getString(code);
}
}
constants.properties
com.curiousby.isdebug=1
代码使用
LoadPropertiesByCode.getTextByCode("com.curiousby.isdebug")
结果:
1
捐助开发者
在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。



谢谢您的赞助,我会做的更好!
本文介绍了一个名为LoadPropertiesByCode的类,用于通过指定的键从配置文件中获取值。具体实现中,利用ResourceBundle类来加载并获取对应的配置属性值。
784

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



