zoukankan      html  css  js  c++  java
  • Java 获取到配置文件信息

    Java程序将数据库或者服务器IP写入到代码中,难免缺少灵活性。

    如果写入到配置文件,部署到不通服务器上,只需要修改配置文

    件即可。

    Java怎么读取配置文件

    	/**
    	 * 获取到配置文件信息
    	 * @param key
    	 * @return
    	 */
    	public  String getConfigValue(String key){
    		String path = this.getClass().getResource("/").getPath(); 
    		InputStream ins =null;
    		try {
    			ins = new BufferedInputStream(new FileInputStream(System.getProperty("user.dir")+"/config/config.properties"));
    		} catch (FileNotFoundException e2) {
    			e2.printStackTrace();
    		}
    		String value="";
    		Properties properties = new Properties();
    			try {
    				properties.load(ins);
    				value= properties.getProperty(key);
    				ins.close();
    			} catch (IOException e1) {
    				e1.printStackTrace();
    			}
    		
    			return value;
    	}


    配置文件格式:

    pwd=root
    username=root
    driverName=com.mysql.jdbc.Driver
    urlString=jdbc:mysql://127.0.0.1:3306/mysql?useUnicode=true&characterEncoding=UTF-8
    htmlUrl=http://10.225.1.136/
    downPath=E:\勘探院采集文件源库\维普\
    dataDownPath=E:\\勘探院采集文件源库\\维普\\
    inputPage=28340
    
    


     

  • 相关阅读:
    opencv图片压缩视频并读取
    python常见模块统计
    MySQL索引及优化
    web开发框架之 Tornado
    Tornado项目基本架构
    python闭包以及装饰器
    python语法糖
    python os模块
    TCP中的3次握手和4次挥手
    Python常见的数据类型方法
  • 原文地址:https://www.cnblogs.com/riasky/p/3473442.html
Copyright © 2011-2022 走看看