读取Properties配置文件
2015-08-25 21:05
399 查看
读取配置文件:
/**
* 通过文件路径载入数据
*
* @param fileName 文件路径
* @return {@link Properties}
*/
public static Properties getPropertiesByFileName(String fileName) {
Properties prop = new Properties();
try (BufferedReader bf = new BufferedReader(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName), "UTF-8"))) {
if (bf == null) {
return prop;
}
prop.load(bf);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return prop;
}
/**
* 通过文件路径载入数据
*
* @param fileName 文件路径
* @return {@link Properties}
*/
public static Properties getPropertiesByFileName(String fileName) {
Properties prop = new Properties();
try (BufferedReader bf = new BufferedReader(new InputStreamReader(PropertiesUtil.class.getClassLoader().getResourceAsStream(fileName), "UTF-8"))) {
if (bf == null) {
return prop;
}
prop.load(bf);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
return prop;
}
相关文章推荐
- Android 读取Properties配置文件的小例子
- java读取properties文件的方法实例分析
- ajax读取properties资源文件数据的方法
- java读取properties文件的方法
- java读取properties配置文件的方法
- java使用POI读取properties文件并写到Excel的方法
- Java遍历Properties所有元素的方法实例
- java处理国际化和读取properties文件代码片段
- 有序的方式读写Properties文件 —— 对java.util.Properties的改写
- log4j.properties配置与加载应用
- 犯了一个愚蠢的错误
- Python实用脚本(1):读取Properties文件
- Java动态给类中配置常量赋值的三种方法
- java读取Properties文件-操作Properties配置文件
- Environment
- java读取配置文件的几种方法
- java读取配置文件的几种方法
- Java读取Properties文件的六种方法(转)
- spring 集成的项目,Properties配置文件外移
- Java的properties文件