工具类---读取配置文件工具类

读取项目配置文件工具类

public class ConfigReaderUtil {
  
	public ConfigReaderUtil(){}
	private static Properties props = new Properties(); 
	static{
		try {
			//加载配置文件,需要手动指定配置文件
			props.load(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("application.properties"),"UTF-8"));		
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/*根据key获取value*/
	public static String getValue(String key){
		return props.getProperty(key).trim();
	}
}
发布了62 篇原创文章 · 获赞 25 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_39115469/article/details/104563432