Properties工具类
2024-09-26 08:23:36
/**
* 加载Properties文件
* @param path Properties文件路径
* @return
*/
private static Properties getClasspathProperties(String path) {
Assert.notNull(path);
InputStream in = null;
try {
File file = new File(SysUtils.class.getResource("/").getPath() + path);
in = new FileInputStream(file); Properties properties = new Properties();
properties.load(in); return properties;
} catch (IOException e) {
throw new SysException("无法读取资源文件:[{}],错误信息:{}", path, e.getMessage());
} finally {
if (null != in) {
try {
in.close();
} catch (IOException e) {
throw new SysException("无法读取资源文件:[{}],错误信息:{}", path, e.getMessage());
}
}
}
}
/**
* 获取Properties中key对应的value值
* @param properties Properties
* @param key 键
* @param defaultValue 默认值
* @return
*/
private static String getProperty(Properties properties, String key, String defaultValue) {
Assert.notNull(properties);
Assert.hasLength(key);
String value = null;
if (properties.containsKey(key)) {
value = properties.getProperty(key);
} else {
LOG.info("未发现配置:" + key);
} if (StringUtils.isBlank(value)) {
value = defaultValue;
}
LOG.debug("获取到值为{}",value);
return value;
}
最新文章
- 头文件 string.h cstring string 区别
- MYSQL例题合集
- HTML5就是现在:深入了解Polyfills
- HDU 1158 Employment Planning【DP】
- FormsAuthentication与Session超时时间不一的解决方法
- win8 64位系统,安装JDK的步骤及其环境配置
- EF-CodeFirst-表关系-延迟/贪婪加载
- Flex中如何通过horizontalTickAligned和verticalTickAligned样式指定线图LineChart横竖方向轴心标记的例子
- J2SE知识点摘记(二十四)
- SSD常见问题的技术分析
- openwrt通过libcurl上传图片,服务器端通过PHP接收文件
- 使用MFC创建C++程序
- ue4 材质表达式分类
- js获取数组中相同元素数量
- Go语言执行流程
- springsession 实现session 共享
- Android 支付密码输入框,自定义EditText实现密码输入框功能;
- FOJ-1058-粗心的物理学家
- 用Python实现多站点运维监控
- 2017中国大学生程序设计竞赛 - 网络选拔赛 HDU 6153 A Secret KMP,思维