public class GetCfg {
private static Properties pro = null;
private static GetCfg getcfg = new GetCfg(); //调用方法之前先初始化static变量
private GetCfg()
{
pro = new Properties(); //new Properties对象
try {
pro.load(this.getClass().getClassLoader().getResourceAsStream("conf.properties")); //读取加载conf.properties文件
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getValue(String key)
{
String v = pro.getProperty(key.trim()).trim(); //通过变量名或得具体的值
return (null == v)? "" : v.trim();
}
public static String getDefaultValue(String key ,String defaultStr)
{
return pro.getProperty(key.trim(), defaultStr).trim();
}
}
读取后缀为properties文件
最新推荐文章于 2023-10-18 20:30:00 发布