Properties文件key值读取
public class PropertiesUtil {
public static String getPropertieValue(String path, String key) {
return getPropertieValue(path, key, null);
}
public static String getPropertieValue(String path, String key, String defaultValue) {
Properties properties = new Properties();
InputStream in = PropertiesUtil.class.getClassLoader().getResourceAsStream(path);
try {
properties.load(in);
} catch (IOException ignore) {
}
String value = properties.getProperty(key);
return value == null ? defaultValue : value;
}
public static void main(String[] args) {
System.out.println(PropertiesUtil.getPropertieValue("jdbc.properties", "jdbc.url", "hello"));
}
}