java加载配置文件信息

#基金数据存放根目录
fund_save_root_path=E:/fundCrawling

#龙虎榜数据存放根目录
long_hu_root_path=E:/longHuCrawling

#巨潮数据存放根目录
ju_chao_root_path=E:/juChaoCrawling


#日k线数据
k_ofday_root_path=E:/kOfDayCrawling


 1 package com.financial.server.util;
 2 
 3 import java.io.File;
 4 import java.io.IOException;
 5 import java.io.InputStream;
 6 import java.util.HashMap;
 7 import java.util.Map;
 8 import java.util.Properties;
 9 
10 import org.springframework.http.StreamingHttpOutputMessage;
11 import org.springframework.web.context.ContextLoader;
12 
13 public class Constants {
14     
15     public static final String ROOT_PATH = ContextLoader.getCurrentWebApplicationContext().getServletContext().getRealPath("").replace("\\",File.separator);
16     
17     //基金相关数据爬取文件存放的根目录  
18     public static String FUND_SAVE_ROOT_PATH;
19    //龙虎榜详情相关数据爬取文件存放的根目录
20     public static String LONG_HU_ROOT_PATH;
21     //巨潮网数据爬取文件存放的根目录
22     public static String JU_CHAO_ROOT_PATH;
23     
24     //日K线数据爬取文件存放的根目录
25     public static String K_OFDAY_ROOT_PATH;
26     
27     static{
28         InputStream inStream = Constants.class.getClassLoader().getResourceAsStream("resourse.properties");
29         Properties prop = new Properties();
30         try {
31             prop.load(inStream);
32         } catch (IOException e) {
33             e.printStackTrace();
34         }
35         FUND_SAVE_ROOT_PATH = prop.getProperty("fund_save_root_path");
36         JU_CHAO_ROOT_PATH = prop.getProperty("ju_chao_root_path");
37         K_OFDAY_ROOT_PATH = prop.getProperty("k_ofday_root_path");
38     }
39 }
View Code

 

posted @ 2018-07-18 10:23  有猿人  阅读(405)  评论(0编辑  收藏  举报