工具类---读取配置文件工具类
读取项目配置文件工具类
package com.ssm.util;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
public class ConfigReaderUtil {
public ConfigReaderUtil(){}
private static Properties props = new Properties();
static{
try {
//加载配置文件,需要手动指定配置文件
props.load(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.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();
}
/*更改配置*/
public static void updateProperties(String key, String value) {
props.setProperty(key, value);
}
}
还没有评论,来说两句吧...