Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Yadrif Rifkin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Yadrif Rifkin
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic