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去获取 ...
随机推荐
- css链接
css code: a:link{ color:#FF0000; } a:visited{ color:#00FF00; } a:hover { color:#0000FF; } a:active{ ...
- Freemarker生成静态代码实例
1.static.html <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http ...
- Android应用程序之间共享文字和图片(二)
MainActivity如下: package cn.testshare1; import java.io.File; import java.util.ArrayList; import andro ...
- 300元差价选谁好 魅蓝note对比魅蓝手机
http://mobile.pconline.com.cn/608/6089437.html [PConline 对比评测]999元的魅蓝note和699元的魅蓝手机先后被发布,代表着魅族中低端手机已 ...
- 基于bootstrap的datatable控件
https://editor.datatables.net/release/DataTables/extras/Editor/examples/bootstrap.htmlhttps://github ...
- 【ThinkingInC++】64、重载new和delete,来模仿内存的分配
/** * 书本:[ThinkingInC++] * 功能:重载new和delete.来模仿内存的分配 * 时间:2014年10月5日14:30:11 * 作者:cutter_point */ #in ...
- Ajax原生XHR对象
前端学了有一段时间了,在项目中我通常使用的都是jQuery封装好的Ajax函数($.ajax.$.get.$.post),使用非常的简单方便,但为了更清楚的了解Ajax,需要学习原生xhr对象. ...
- c#中从string数组转换到int数组
以前一直有一个数组之间转换的东西,可是忘记了,今天也是找了好久也没有解决,最后用这种方法解决了,分享给大家. " }; int[] output = Array.ConvertAll< ...
- hdu 1076
水题 AC代码: #include <iostream> using namespace std; int main() { int i,k,t,y,n; cin>>t; wh ...
- (转)jQuery插件开发全解析
jQuery插件的开发包括两种: 一种是类级别的插件开发,即给jQuery添加新的全局函数,相当于给jQuery类本身添加方法.jQuery的全局函数就是属于jQuery命名空间的函数,另一种是对象级 ...