首页 > 其他 > 详细

读取config配置信息

时间:2015-03-21 16:50:25      阅读:356      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!