• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

reading properties file

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think so. Write you're own if you really need this option.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic