| Author |
reading properties file
|
Jeffrey Pony
Greenhorn
Joined: Jun 24, 2002
Posts: 25
|
|
Iam currently using jdk1.4. I have a to read a properties file containing text, key = value spaced key = spaced value Can I set the delimiter that is to be used by Properties, in this case I would want only '=' as the delimiter and ignore whilte space between the keys. Is there any way that I can acheive this in my code while creating the Properties object or invoking the load method? Thanks in advance.
|
 |
Filip Pas
Greenhorn
Joined: Apr 22, 2005
Posts: 12
|
|
|
I don't think so. Write you're own if you really need this option.
|
 |
Glen Kidston
Greenhorn
Joined: Feb 26, 2005
Posts: 9
|
|
Try escaping the space in the property value with a "\". Here's an example: "Blah.properties" follows:
foo=bar my\ blah=Bling
Note the backslash in property key "my blah". We can test as follows: Running this results in the following output:
my blah: Bling foo: bar
Ta Dah! Um though, I didn't try going the other way, list()ing it to a file or serializing it to an ObjectOutputStream, but I'm guessing it might work... Good Luck! -Glen
|
 |
Glen Kidston
Greenhorn
Joined: Feb 26, 2005
Posts: 9
|
|
Just tried spicing up the Properties key with an embedded "\"" and list()ing to a file: New Blah.properties:
foo=bar my\ \"blah=Bling
New PropTest.java: Which results in:
my "blah: Bling foo: bar Now save it to a file:
All of this really makes sense as, to quote from the java.util.Properties docs:
Each key and its corresponding value in the property list is a string.
|
 |
 |
|
|
subject: reading properties file
|
|
|