首页 > 如何动态修改属性文件×××.properties的某些内容

如何动态修改属性文件×××.properties的某些内容

我们在项目中可以把一些属性配置到×××.properties中,比如数据库连接信息。现在问题来了,我的属性文件中有一些值是需要根据后台得到的数据来动态改变的,请问这个要怎么实现?java或者flex都行,谢谢。


需要动态获取的数据,为什么要写在properties文件中?
直接动态从后台获取就可以了啊,这跟从properties文件读取是两种不同的配置方案


http://crunchify.com/java-properties-file-how-to-read-config-properties-values-in-java/


      // 读取配置文件
      FileInputStream inputStream = new FileInputStream(path);
      Properties prop = new Properties();
      // 加载
      prop.load(inputStream);
      // 获取
      prop.getProperty("key");
      // 设置
      prop.setProperty("key", "value");
      // 写到配置文件
      FileOutputStream outputStream = new FileOutputStream(path);
      prop.store(outputStream, "update message");
      outputStream.close();
【热门文章】
【热门文章】