import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* @author Sam
* @Description: 读取配置工具类
* @date 2018/5/23
*/
public class PropertiesUtils {
private static Properties props;
static {
loadProps();
}
synchronized static private void loadProps() {
props = new Properties();
InputStream in = null;
try {
// 要加载的属性文件
in = PropertiesUtils.class.getResourceAsStream("/config.properties");
props.load(in);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (null != in) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static String getProperty(String key) {
if (null == props) {
loadProps();
}
return props.getProperty(key);
}
public static String getProperty(String key, String defaultValue) {
if (null == props) {
loadProps();
}
return props.getProperty(key, defaultValue);
}
}
读取配置工具类
最新推荐文章于 2022-08-12 15:37:49 发布