Properties类
作者:互联网
Properties类
Properties 类是 Hashtable 的子类,该对象用于处理属性文件
//Properties:常用来处理配置文件。key和value都是String类型
public static void main(String[] args) throws IOException {
FileInputStream fileInputStream = null;
try { //快捷键ctrl alt T
Properties pros = new Properties();
fileInputStream = new FileInputStream("jdbc.properties");
pros.load(fileInputStream);//加载流对应的文件
String name = pros.getProperty("name");
String password = pros.getProperty("password");
System.out.println(name+"====="+password);
} catch (IOException e) {
e.printStackTrace();
}finally {
if (fileInputStream!=null){
try {
fileInputStream.close();
}catch (IOException e){
e.printStackTrace();
}
}
}
}
jdbc.properties文件:
name=Tom
password=abc123
标签:name,pros,fileInputStream,password,Properties,String 来源: https://www.cnblogs.com/blwx/p/16685770.html