Home  >  Q&A  >  body text

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

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

黄舟黄舟2754 days ago864

reply all(3)I'll reply

  • 迷茫

    迷茫2017-04-17 13:02:09

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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:02:09

    Why should the data that needs to be obtained dynamically be written in the properties file?
    Just 动态从后台获取 is enough. These are two different configuration plans from 从properties文件读取

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 13:02:09

          // 读取配置文件
          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();
    

    reply
    0
  • Cancelreply