欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Properties文件读取工具类

程序员文章站 2022-05-10 08:45:17
...
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));
	}
}

 

相关标签: Properties