File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Being able to not escape Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Being able to not escape ":" in key in properties file" Watch "Being able to not escape ":" in key in properties file" New topic
Author

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

Yadrif Rifkin
Greenhorn

Joined: Oct 22, 2010
Posts: 2
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

Joined: Oct 27, 2005
Posts: 19695
    
  20

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).


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Yadrif Rifkin
Greenhorn

Joined: Oct 22, 2010
Posts: 2
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Being able to not escape ":" in key in properties file