PropGetKit.java 1.1 KB
Newer Older
T
Tom Qian 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
/**
 * 
 */
package top.qianxinyao.algorithms;

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

import org.apache.log4j.Logger;

/**
 * @author qianxinyao
 * @email tomqianmaple@gmail.com
 * @github https://github.com/bluemapleman
 * @date 2016年11月30日 用以读取配置文件,获取对应属性
 */
public class PropGetKit
{
	private static final Logger logger = Logger.getLogger(PropGetKit.class);

	public static Properties propGetKit = new Properties();;

	public static void loadProperties(String configFileName)
	{
		try
		{
			propGetKit.load(new FileInputStream(System.getProperty("user.dir") + "/res/" + configFileName + ".properties"));
		}
		catch (FileNotFoundException e)
		{
			logger.error("读取属性文件--->失败!- 原因:文件路径错误或者文件不存在");
		}
		catch (IOException e)
		{
			logger.error("装载文件--->失败!");
		}
	}

	public static String getString(String key)
	{
		return propGetKit.getProperty(key);
	}
	
	public static int getInt(String key)
	{
		return Integer.valueOf(propGetKit.getProperty(key));
	}
	
}