1.读取配置文件的油条类

package com.sinohonour.ciprobe.routor.api.utils;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class PropUtil {
	/**
	* @author Liliang Zuo
	* @date : 2017年10月16日 上午10:07:11
	*/
	private static Properties prop = null;
	private PropUtil() {}
	static{
		try {
			prop = new Properties();
			prop.load(new FileInputStream(PropUtil.class.getClassLoader().getResource("routor.properties").getPath()));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 获取properties对象
	 * 
	 * @author Liliang Zuo
	 * @data 2017年10月16日
	 * @return 返回properties对象
	 */
	public static Properties getProperty(){
		return prop;
	}
	/**
	 * 获取properties对象中key对应的value值
	 * 
	 * @author Liliang Zuo
	 * @data 2017年10月16日
	 * @param str 传入的key
	 * @return 返回key对应的value
	 */
	public static String getProperty(String str){
		return prop.getProperty(str);
	}
}

在src下创建properties文件即可使用


猜你喜欢

转载自blog.csdn.net/tansuoliming/article/details/80863921
今日推荐