properties 文件的加载,修改保存

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhao__zhen/article/details/83690456

properties 文件的加载,修改保存

  1. properties 文件的加载
Properties prop = new Properties();
prop.load(this.getClass().getResourceAsStream("/conf.properties"));
prop.get("KEY");
  1. properties 文件的修改保存
JSONObject jsonObject = JSONObject.fromObject(str);
prop.setProperty("ys.Token", (String) JSONObject.fromObject(jsonObject.get("data")).get("accessToken"));
URL confUri = this.getClass().getResource("/conf.properties");
FileOutputStream fos = new FileOutputStream(new File(confUri.toURI()));
prop.store(fos, "new token");//文件名和路径
System.out.println(prop.get("ys.Token")+"new token");

猜你喜欢

转载自blog.csdn.net/zhao__zhen/article/details/83690456