import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
/**
* 读取配置文件 config.properties
* @author LN
*
*/
public class PropertyUtil {
public static void main(String[] args) {
String url1=getProperty("interfa");
System.out.println("url1:"+url1);
String url2=getProperty("inter ", "http://127.0.0.1");
System.out.println("url2:"+url2);
}
public static String getProperty(String key){
InputStream in = PropertyUtil.class.getResourceAsStream("/config.properties");
Properties properties = new Properties();
String value;
try {
properties.load(in);
value = properties.getProperty(key);
in.close();
return value;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static String getProperty(String key,String value){
InputStream in = PropertyUtil.class.getResourceAsStream("/config.properties");
Properties properties = new Properties();
try {
properties.load(in);
value = properties.getProperty(key);
in.close();
return value;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}