How to reload properties file in java

前端 未结 2 499
一向
一向 2020-12-11 17:11

Anyone please help me on reloading properties file. I have code like this

Properties prop = new Properties();
InputStream trackerFileStream = 
    LoadProper         


        
相关标签:
2条回答
  • 2020-12-11 17:40

    If you want to be updated you need to check the resource from tome to time and reload the properties.

    It is a problem that you are loading properties from classpath. If you use file system you can check the last modified attribute of file and decide whether to reload it. In java 7 you evern can register listener that will call you back when file is modified. You can't do this when loading resource.

    But you can do better. Use configuration package from apache. It already implements reloading logic, so you just can work against "configuration" actually mapped to resource and be sure you always get updated data.

    0 讨论(0)
  • 2020-12-11 17:40

    Do you close/flush your streams correctly? Why using classloader to access the file? If the file is an external file you should access it via normal FileInputStream for example

    0 讨论(0)
提交回复
热议问题