Properties集合类的练习
Properties中存储的都是键值对,用=连接
public static void main(String[] args) throws IOException {
Properties pro = new Properties();
//获取src路径下文件的相对路径
ClassLoader classLoader = PropertiesDemo.class.getClassLoader();
URL resource = classLoader.getResource("jdbc.properties");
//得到的是一个对象
String path = resource.getPath();
FileReader fr = new FileReader(path);
//加载文件
pro.load(fr);
//获取数据
String url = pro.getProperty("url");
String user = pro.getProperty("user");
String password = pro.getProperty("password");
String driver = pro.getProperty("driver");
System.out.println(url);
System.out.println(user);
System.out.println(password);
System.out.println(driver);
fr.close();
}
来源:https://blog.csdn.net/TTTiaotiao/article/details/99551056