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 reading properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "reading properties file" Watch "reading properties file" New topic
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.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: reading properties file
 
Similar Threads
read a .txt file from classpath
how to use the .prp file
Maintaining the order in a collection.
Reading Properties file with spaces in key
how to reference already defined property as the value for another key in the properties file.