spring加载properties配置文件
2013-08-05 17:20
411 查看
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;
}
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配置文件的四种方式
- IDEA spring的xml配置文件加载不到properties属性问题
- spring基于xml加载和读取properties配置文件的方式
- 可以从Jar外部加载JDBC.properties的Spring-mybatis配置文件
- 参数配置文件properties--使用spring加载和简化读取
- spring加载配置属性文件(properties)
- spring加载properties配置文件
- Spring配置中从外部文件加载多个properties文件
- For input string: "${JDBC.MinPoolSize}" spring加载jdbc.properties配置文件报错
- 使用Spring加载properties配置文件.md
- IDEA spring的xml配置文件加载不到properties属性问题
- springboot 修改默认加载的配置文件不为application.properties
- [Spring boot]配置文件properties加载
- Spring中加载多个Properties配置文件
- Spring加载properties配置资源文件的应用
- Spring加载Properties配置文件的加密解密处理
- Spring配置文件加载properties文件
- 解决eclipse创建spring boot项目加载不到application.properties配置文件的问题
- 详解Spring加载Properties配置文件的四种方式