zoukankan      html  css  js  c++  java
  • Java获取配置文件参数工具类

    package com.bo.test;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.net.URISyntaxException;
    import java.util.Properties;
    
    /**
     * 数据库访问配置文件各参数的获取
     * 将配置文件pdf.properties放在 项目Src下
     * fdriver =oracle.jdbc.driver.OracleDriver
    furl =jdbc:oracle:thin:@192.168.12.247:1521:oracle
    fuser =hhris
    fpassword =hhris
     * @author YaoYuanBo
     *
     */
    public class DbConfig {
        //数据库及server配置文件路径
        private static final String ACTIONPATH = "pdf.properties";  
        private static DbConfig instance=null;
        
        private String bo_fdriver=null;
        private String bo_furl=null;
        private String bo_fuser=null;
        private String bo_fpassword=null;
        
        
        private DbConfig(){}
        
        public static String getActionpath() {
    		return ACTIONPATH;
    	}
    
    	public String getBo_fdriver() {
    		return bo_fdriver;
    	}
    
    
    	public String getBo_furl() {
    		return bo_furl;
    	}
    
    
    	public String getBo_fuser() {
    		return bo_fuser;
    	}
    
    	public String getBo_fpassword() {
    		return bo_fpassword;
    	}
    
    
    	public static DbConfig getInstance(){
            if(instance==null){
                instance= new DbConfig().getNewDbConfig();
            }
            return instance;
        }
        
        private DbConfig getNewDbConfig(){
            
            DbConfig dc=new DbConfig();
            Properties prop = new Properties();  
            String path=null;
            FileInputStream fis=null;
            
            try {
                path = DbConfig.class.getClassLoader().getResource("").toURI().getPath();
                fis = new FileInputStream(new File(path + ACTIONPATH));
                prop.load(fis);
                dc.bo_fdriver=prop.getProperty("fdriver"); 
                dc.bo_furl=prop.getProperty("furl"); 
                dc.bo_fuser=prop.getProperty("fuser"); 
                dc.bo_fpassword=prop.getProperty("fpassword"); 
            
            } catch (URISyntaxException e) {
                e.printStackTrace();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }  
            
            return dc;
        }
    }
    

      

  • 相关阅读:
    放假归来
    用ObjectSpaces重建IBuySpy的数据访问层
    在SPS中加入自定义WebService
    AnnouncementOSD.xml
    Delphi8 is out !
    ASP.NET PreCompilation and KeepAlive
    ScottGu回答了Whidbey发布的时间问题
    DiskBased Caching in Whidbey, Longhorn…
    AnnouncementRSD.xml
    忙着满足客户的需求...
  • 原文地址:https://www.cnblogs.com/forever2698/p/4754220.html
Copyright © 2011-2022 走看看