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;
    }
}

  

转载于:https://www.cnblogs.com/forever2698/p/4754220.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值