6 Replies Latest reply: Sep 7, 2007 5:41 AM by 807600 RSS

    Properties file question

    807600
      Hi all,

      I have a property file to which a user adds more data manually. I am looking for ways to read this file in a way that my code also reads the new values when it executes. What is the best solution to such read a dynamically changing property file ?

      For example if my file has

      ProductID
      ProductName

      At a later time the user manually includes

      SupplierID

      My program should read this value also when it executes next time.

      I know the usually way to reading the property file :
                     
        
                              Properties m_properties=new Properties();
      
                            //Here there is code to open inputstream and load properties
                     
                     // Get the properties of each
                     String strurl = oProperties.getProperty("STR_URL");
      Any new ideas ??

      thanks in advance

      @debug.
        • 1. Re: Properties file question
          807600
          You need to re-load the properties before every access, if they're changing all the time at runtime
          • 2. Re: Properties file question
            807600
            Thanks for the reply. But the question is as follows:

            In the following line the code already knows about "STR_URL" but when the user adds new property "STR_VERSION" there is no line of code which gets the property for this key.
            String strurl = oProperties.getProperty("STR_URL");
            I am just looking for ideas where the code should not depend on "STR_VERSION".....
            • 3. Re: Properties file question
              807600
              How are you going to make use of the property, if nothing is aware of it? What are you actually trying to do?
              • 4. Re: Properties file question
                807600
                I want to read all the properties in a properties file in one String at runtime and display them to the user. Of course, I will play with that string later ??

                Message was edited by:
                @debug
                • 5. Re: Properties file question
                  807600
                  I want to read all the properties in a properties
                  file in one String and display them to the user. Of
                  course I will play with that string later ??
                  Ah. Somewhat different from your initial question!

                  Properties implements Map, so you can ask it for it's keySet, entrySet or values, depending on exactly what you want. If you're interested in both the key and the value, get the entrySet (it's a Set<Map.Entry>) and ask the entry for the key and the value as you require. The Entry will return Objects, but you can be pretty safe casting them to Strings to do whatever you want with them
                  • 6. Re: Properties file question
                    807600
                    Ok, I will try that. Thanks.