spring加载properties配置文件
public static void main(String[] args){
String path="E:/workspace/bocMarketData/src/config/PeriodCode.properties";
try {
Map<String,String> periodCodeMap =readConfigForMap(path);
Set<String> set1 = periodCodeMap.keySet();
for (String s:set1) {
System.out.println(s+","+periodCodeMap.get(s));
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 读取文件,生成 Map<String,String>,左边为key 右边为value
* @param path
* @return
* @throws Exception
*/
public static Map<String,String> readConfigForMap(String path) throws Exception{
BufferedReader bf=null;
try{
InputStream in = new FileInputStream(new File(path));
// path E:/workspace/eDealingV3.0_eTof/src/conf/config/institutionl_IP_Config.properties
Reader reader = new InputStreamReader(in);
bf=new BufferedReader(reader);
}catch(Exception e){
e.getMessage();
}
String row=null;
Map<String,String> sMap = new HashMap<String, String>();
while(null!=(row=bf.readLine())){
if(!row.equals("")){
if(row.startsWith("#")){
continue;
}
String key = row.substring(0, row.indexOf("="));
String value = row.substring(row.indexOf("=")+1,row.length());
sMap.put(key, value);
}
}
bf.close();
return sMap;
}
spring加载properties配置文件的更多相关文章
- 使用Spring加载properties配置文件.md
背景 类似于datasource.properties之类的配置文件,最初通过Java的Properties类进行处理.这种方式有许多弊端,如每次都需要读取配置文件:若将Properties作为成员变 ...
- Spring加载Properties配置文件的三种方式
一.通过 context:property-placeholder 标签实现配置文件加载 1) 用法: 1.在spring.xml配置文件中添加标签 <context:property-plac ...
- Spring加载properties文件的两种方式
在项目中如果有些参数经常需要修改,或者后期可能需要修改,那我们最好把这些参数放到properties文件中,源代码中读取properties里面的配置,这样后期只需要改动properties文件即可, ...
- Java加载Properties配置文件工具类
Java加载Properties配置文件工具类 import org.apache.commons.lang3.StringUtils; import org.apache.log4j.Logger; ...
- 加载Properties配置文件
/** * 加载Properties配置文件 * * @author ZhangHaiNing * @param file 要读取的文件 * @return */ public static Prop ...
- Spring加载properties文件的属性的值
要使用配置文件的值首先在spring.xml配置加载properties文件 <context:property-placeholder location="classpath:ife ...
- spring加载属性配置文件内容
在spring中提供了一个专门加载文件的类PropertyPlaceholderConfigurer,通过这个类我们只需要给定需要加载文件的路径就可以 通过该类加载到项目,但是为了后面在程序中需要使用 ...
- Spring加载xml配置文件的方式 ApplicationContext
大家都知道Java读普通文件是通过Basic I/O 中的InputStream.OutStream.Reader.Writer 等实现的.在spring 框架中,它是怎样识别xml这个配置文件的呢? ...
- Spring加载XML配置文件
原创链接:http://www.cnblogs.com/yanqin/p/5282929.html(允许转载,但请注明原创链接) BeanFactory加载单个文件 当使用beanfactory去获取 ...
随机推荐
- POJ 2455Secret Milking Machine(二分+网络流之最大流)
题目地址:POJ2455 手残真浪费时间啊..又拖到了今天才找出了错误..每晚两道题不知不觉又变回了每晚一道题...sad.. 第一次在isap中忘记调用bfs,第二次则是遍历的时候竟然是从1開始遍历 ...
- Linux下rar unrar的安装
Linux下rar unrar的安装: 以3.8.0版本为例,如果是64位平台,执行以下命令,也可以去官方网站:)下载最新版: wget http://www.rarlab.com/rar/rarli ...
- 【转】UIKit性能调优实战讲解
文/bestswifter(简书作者)原文链接:http://www.jianshu.com/p/619cf14640f3著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 在使用UIKi ...
- 解决sql2008连接数据库,无法为该请求检索数据,错误916
通常在使用sql server management studio 2008 连接数据库,可以链接上,但是无法查看自己的数据库,点击数据库或刷新数据库列表后,提示:无法为该请求检索数据,错误916,如 ...
- Aspose.Cells for .NET 8.5.0 工具类
基于 Aspose.Cells for .NET 8.5.0 工具类, Aspose.Cells for .NET 8.5.0 这个自己去CSDN下载里面有破解的,没有破解的导出excel的时候会(A ...
- sql 字段字符串内容替换
SELECT * FROM dbo.Table WHERE Name LIKE '%NYCL23%'UPDATE Table SET Name=replace(Name,'NYCL23','WYCL1 ...
- 如何读懂SQL Server的事务日志
简介 本文将介绍SQL Server的事务日志中记录了哪一些信息,如何来读懂这些事务日志中信息.首先介绍一个微软没有公开的函数fn_dblog,在文章的接下来的部分主要用到这个函数来读取事务日志. f ...
- Sql Server 2008清理数据库日志的语句
USE [master]GOALTER DATABASE DNName SET RECOVERY SIMPLE WITH NO_WAITGOALTER DATABASE DNName SET RECO ...
- Sql省市三级联动一张表
CREATE TABLE [dbo].[region]( [region_id] [int] NULL, [region_name] [varchar](50) COLLATE Chinese_PRC ...
- hdu2937
题目大意: 给出n求sn,中括号代表向下取整. 为了方便表述,我们令a = (3k+6)!,b = (3k+7),令c = (a+1)/b也就是式子中的前半部分,d = a/b也就是式子中的后半部分. ...