我有一个属性文件(在 rsources 文件夹下),我在其中存储了一个变量(键=值),
当用户插入新值或更新旧值时,我需要更新它,我可以这样做吗? 我有疑问,因为它是一个 Web 应用程序,所以它只是部署在服务器中的一场 war 。那么如何访问 .properties 文件并直接从代码中更改它呢?
如果不行,是否有其他解决方案?
最佳答案
也许用户可以在文件系统中提供一个覆盖属性文件,其值将覆盖打包的默认属性文件。
查看 Apache Commons Configuration ,这permits this capability .
Often you want to provide a base set of configuration values, but allow the user to easily override them for their specific environment. Well one way is to hard code the default values into your code, and have then provide a property file that overrides this. However, this is a very rigid way of doing things. Instead, with the CompositeConfiguration you can provide many different ways of setting up a configuration.
关于java - 更新 Web 应用程序中的属性文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13950743/