博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Properties工具类
阅读量:6870 次
发布时间:2019-06-26

本文共 1713 字,大约阅读时间需要 5 分钟。

1 /** 2      * 加载Properties文件 3      * @param path Properties文件路径 4      * @return 5      */ 6     private static Properties getClasspathProperties(String path) { 7         Assert.notNull(path); 8         InputStream in = null; 9         try {10             File file = new File(SysUtils.class.getResource("/").getPath() + path);11             in = new FileInputStream(file);12             13             Properties properties = new Properties();14             properties.load(in);15             16             return properties;17         } catch (IOException e) {18             throw new SysException("无法读取资源文件:[{}],错误信息:{}", path, e.getMessage());19         } finally {20             if (null != in) {21                 try {22                     in.close();23                 } catch (IOException e) {24                     throw new SysException("无法读取资源文件:[{}],错误信息:{}", path, e.getMessage());25                 }26             }27         }28     }29     /**30      * 获取Properties中key对应的value值31      * @param properties Properties32      * @param key 键33      * @param defaultValue 默认值34      * @return35      */36     private static String getProperty(Properties properties, String key, String defaultValue) {37         Assert.notNull(properties);38         Assert.hasLength(key);39         String value = null;40         if (properties.containsKey(key)) {41             value = properties.getProperty(key);42         } else {43             LOG.info("未发现配置:" + key);44         }45         46         if (StringUtils.isBlank(value)) {47             value = defaultValue;48         }49         LOG.debug("获取到值为{}",value);50         return value;51     }

 

转载于:https://www.cnblogs.com/sun-space/p/5536422.html

你可能感兴趣的文章
《IPv6精髓(第2版)》——导读
查看>>
《Windows Server 2012 Hyper-V虚拟化管理实践》一1.2 Hyper-V安装前后的变化
查看>>
Proxmox VE 4.4 发布,新 Ceph 仪表盘上线
查看>>
《CCNP TSHOOT(642-832)学习指南》一1.2 维护进程及维护流程
查看>>
华为宣布开源流处理平台查询语言 StreamCQL
查看>>
2016 年 6 月 RedMonk 编程语言排行榜
查看>>
《Adobe Photoshop CC经典教程(彩色版)》—第1课1.4节在Photoshop中还原操作
查看>>
HttpClient使用详解
查看>>
增强现实?先不要指望那些眼镜了
查看>>
《iOS 6核心开发手册(第4版)》——1.10节秘诀:使用多触摸交互
查看>>
《云数据管理:挑战与机遇》一第1章
查看>>
《嵌入式C编程实战》——1.5 软件开发工具
查看>>
分析3000份技术面试数据:这几大指标比你毕业于哪所学校更要紧
查看>>
Linux有问必答:如何检查PDF中使用了哪种字体
查看>>
《Lua游戏AI开发指南》一2.1 新建一个沙箱项目
查看>>
如何使用 Weave 以及 Docker 搭建 Nginx 反向代理/负载均衡服务器
查看>>
《Android 应用测试指南》——第1章,第1.4节测试的种类
查看>>
对jquery val 获取input 文本框值进行扩展
查看>>
MySQL (select_paren) union_order_or_limit 行为
查看>>
并发不是并行,它更好!
查看>>