Properties文件读取工具类

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class BasePropertiesUtils 
{
	private static Properties properties = null;
	
	private synchronized static void init()
	{
		properties = new Properties();
		
		try(InputStream input = ClassLoader.getSystemResourceAsStream("application.properties"))
		{
			properties.load(input);
		}
		catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	
	public static String getValue(String key){
		if(properties==null){
			init();
		}
		return properties.getProperty(key).trim();
	}
	
	public static Integer getIntValue(String key)
	{
		return Integer.valueOf(getValue(key));
	}
}

猜你喜欢

转载自zhongmin2012.iteye.com/blog/2307132