public class demo {
private static String CONFIG_FILE= "client.properties";
//java jdk提供读取配置文件工具类
private static Properties props=new Properties();
public static void main(String[] args){
String value =getconfigValue("client.authen.server.slaver.host");
System.out.println("配置文件中的值是:"+value);
}
public static String getconfigValue(String key){
String value=null;
try {
InputStream in = demo.class.getClassLoader().getResourceAsStream(CONFIG_FILE);
if(in!=null){
props.load(in);
value = props.getProperty(key);
in.close();
}
}catch(Exception e){
}
return value;
}
}
获取类文件同级目录下配置文件中的值
最新推荐文章于 2024-05-18 16:42:38 发布