Forums Register Login

Being able to not escape ":" in key in properties file

+Pie Number of slices to send: Send
Hi.

I would like to have a properties file where the key will contain colon characters (usually a lot of them). For example:

::level1::level2::level3::Etc=TheFileForThisStuff.txt

The problem is it seem like property file key/value pairs are delimited by the ":" and I can not find a way to change that. Someone suggested I use Properties.load(InputStream inStream) but in reading the documentation I found:
"The key contains all of the characters in the line starting with the first non-white space character and up to, but not including, the first unescaped '=', ':'...."

I do not want people to have to escape all of the ":"'s.

Is there a way to do this?

Thanks.
+Pie Number of slices to send: Send
Why would you want to use :: as separators? What's wrong with simple dots (.)?

Anyway, if you want to continue down this path you must write your own reading routine. And also your own write routing, because I think that Properties escapes : when writing (at least for values).
+Pie Number of slices to send: Send
I do need to stick with "::" as separator. It is out of my control.

By "write your own reading routine" do you mean I can not use Properties class? Just read the file and parse.

Thanks.
+Pie Number of slices to send: Send
 

Yadrif Rifkin wrote:I do need to stick with "::" as separator. It is out of my control.



And likewise the rules for escaping in Properties files are also out of your control. So if your design says you're using a Properties file, and you have users who are typing data into these Properties files, it follows that they must be trained to do it properly.

If you don't like that, then obviously you have two alternatives, which have already been explored:

(1) Don't use characters as separators which must be escaped (although you will eventually run into other characters which must be escaped)

(2) Don't use Properties.load() to read these files (in which case you will have to design your own escaping rules)
Does this tiny ad smell okay to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 8247 times.
Similar Threads
Store() Unicode in Properties file
Ant build fail, sometimes 'cause ant forgets property
Properties.load() ignores '\'
how to retieve the keys and values from a propertyfile in an order
Problem in writing special charactes to a proeprties file
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 08:15:26.