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

      

  • 相关阅读:
    ZOJ 2158 Truck History
    Knight Moves (zoj 1091 poj2243)BFS
    poj 1270 Following Orders
    poj 2935 Basic Wall Maze (BFS)
    Holedox Moving (zoj 1361 poj 1324)bfs
    ZOJ 1083 Frame Stacking
    zoj 2193 Window Pains
    hdu1412{A} + {B}
    hdu2031进制转换
    openjudge最长单词
  • 原文地址:https://www.cnblogs.com/forever2698/p/4754220.html
Copyright © 2011-2022 走看看