3 Replies Latest reply: Dec 13, 2010 11:29 AM by tschodt RSS

    properties file with spaces in key.

    user10260017
      Hi,

      I need to parse a properties file which have space in the key.

      ex: First Name = xxx

      loadUserProperties.getProperty("First Name") is throwing null pointer exception.

      Any clue on how to over come this as this file is provided by some third party and I have no control on the keys in the file. I need to get the values from that properties file for further processing.

      Thanks in advance.
        • 1. Re: properties file with spaces in key.
          452196
          You'll just have to write your own code to read the file. Shouldn't be hard (especially if the values don't contain escape sequences.) Just find the = then process the strings each side of it as required.
          • 2. Re: properties file with spaces in key.
            800330
            Read [url http://forums.oracle.com/forums/message.jspa?messageID=9175527]this post or consult the API documentation.
            • 3. Re: properties file with spaces in key.
              tschodt
              user10260017 wrote:
              I need to parse a properties file which has entries which have space in the key.

              like:
              First\ Name = xxx
              loadUserProperties.getProperty("First Name") is throwing null pointer exception.
              It does not throw NPE for me...
              ... this file is provided by some third party and I have no control on the keys in the file.
              Unless the spaces in the keys are escaped
              the supplier of the file has a problem.
              I need to get the values from that properties file for further processing.
              java.util.Properties gives you propertyNames() and it extends Hashtable so you get elements(), entrySet(), keys(), keySet()
              so that should not be a problem.

              Edited by: tschodt on Dec 13, 2010 5:28 PM