根据key从Properties文件中加载指定的value
2017-01-09 15:36
351 查看
//单例模式实现读取***.properties文件的内容 public class OVLoadProperties { // 声明一个自己的实例 private static OVLoadProperties instance = new OVLoadProperties(); final static String fileName = "/messages_zh_CN.properties"; // 返回该实例 public static synchronized OVLoadProperties getInstance() { return instance; } // 获取key所对应的值 public String getProperties(String key) { Properties p = new Properties(); InputStream is = null; try { // ***.properties文件放在src目录的下边 is = OVLoadProperties.class.getResourceAsStream(fileName); if (is == null) is = new FileInputStream(fileName); p.load(is); } catch (Exception e) { System.out.println("加载文件出错啦!" + e.getMessage()); } finally { if (is != null) { try { is.close(); } catch (IOException e) { // TODO Auto-generated catch block System.out.println(e.getMessage()); } } } return p.getProperty(key); } }
相关文章推荐
- Java获取.properties配置文件某一项value根据key值
- java读取和遍历properties文件并根据key进行排序
- 来段代码提提神-Java读取config.properties文件中的key=value
- 通过java.util.Properties类来读取.properties文件中key对应的value
- Spring 读取properties文件key+value方式
- PropertyPlaceholderConfigurer获取属性文件指定key的value值
- springboot 修改启动时默认加载application.properties文件以及加载指定配置文件
- 详解Jquery EasyUI tree 的异步加载(遍历指定文件夹,根据文件夹内的文件生成tree)
- 根据properties配置文件加载DB-Util帮助类
- Javaweb项目不用重启加载properties文件的方法(根据时间戳来判断)
- Android根据文件路径加载指定文件
- Jquery EasyUI tree 的异步加载(遍历指定文件夹,根据文件夹内的文件生成tree)
- c语言 读取文件的每一行; 查找指定key的value
- java获取配置文件及根据key获取配置文件中的value的工具类
- 通过key获取properties配置文件的value
- android--------根据文件路径加载指定文件
- Bug 加载文件提示错误 : jdbc.properties (系统找不到指定的文件。)
- Spring加载properties文件指定编码方式
- spring加载properties文件,并将属性值注入到指定类的指定成员变量
- android--------根据文件路径加载指定文件