Saving to properties file escapes :

前端 未结 2 1376
挽巷
挽巷 2020-12-11 02:16

Does anyone know why the colons are getting escaped when I store the properties file?

I\'m doing this:

Properties prop = new Properties();


// Set t         


        
相关标签:
2条回答
  • 2020-12-11 02:52

    In properties files, both of these are legit:

    key1 = value
    key2: value
    

    So both = and : must be escaped.

    Now, if you read the thing back with Properties, it's no problem. Otherwise, you'll have to write custom code

    0 讨论(0)
  • 2020-12-11 02:56

    That's what the store() API does:-

    Each character of the key and element strings is examined to see whether it should be rendered as an escape sequence. The ASCII characters \, tab, form feed, newline, and carriage return are written as \, \t, \f \n, and \r, respectively. Characters less than \u0020 and characters greater than \u007E are written as \uxxxx for the appropriate hexadecimal value xxxx. For the key, all space characters are written with a preceding \ character. For the element, leading space characters, but not embedded or trailing space characters, are written with a preceding \ character. The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded.

    It shouldn't really matter to you as long as you use Properties to get the values.

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