码迷,mamicode.com
首页 > 其他好文 > 详细

读取config配置信息

时间:2015-03-21 16:53:36      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:

//config.properties中配置了数据库配置的相关信息,通过这个单例模式设计来实现解耦。
public class PathConfig {	
	private static PathConfig instance = null;
	private String dataPath = null;
	private PathConfig(){
		InputStream in = getClass().getResourceAsStream("/config.properties");
		Properties p = new Properties();
		try {
			p.load(in);
			url = p.getProperty("DBURL", "");
                        username = p.getProperty("DBUSER", "");
                        password = p.getProperty("DBPASS", "");
                }catch(IOException e){
                        e.printStackTrace();
                }
      }
      public static synchronized PathConfig getInstance(){
               if(instance == null){
                    instance = new PathConfig();
               }
               return instance;
     }
}

config.properties:

DBURL=jdbc:oracle:thin:@xxx.xxx.x.x:1521:XE
DBUSER=xxxxx
DBPASS=xxxxx

 

读取config配置信息

标签:

原文地址:http://www.cnblogs.com/sunyt/p/4355672.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!