aspose file tools*
The moose likes Java in General and the fly likes Reading multiple values from a properties file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Reading multiple values from a properties file." Watch "Reading multiple values from a properties file." New topic

Reading multiple values from a properties file.

David C Shaw

Joined: Nov 05, 2010
Posts: 2
Hi all,

I've had a search and while a few have asked something similar I've not seen a working answer as of yet. In short I'm using java to query a properties file and run a password encryption app against all DB connections. In real world terms the process is:

read property->Identify DB connections->prompt user for password to DB user->Run encrypter against password entry -> write encrypted value back out to property file.

My properties look similar to the below but also contain information on applications, urls etc :

xadatasource.SETDataTxDs_1.globalTransaction = TwoPhaseCommit

My property file will no doubt have a few connections. I've used pro.keyset which reads all of the file. Essentially what I need is a bit of code that does:

I've done similar in jython before as you can probably see with my logic above, however with jython using weblogic's WLST it is impossible to mask password inputs so I'm having to add a small java applet to my build.xml to handle this for me.

Any help greatly appreciated.

Many thanks!

(ps. my middle name is Charles, I'm not taking the mick with my display name - thanks Mum n Dad!)
Steve Luke

Joined: Jan 28, 2003
Posts: 4176

Hi David,

It looks like you have a hierarchy in your properties file based on the key string. For example:
represents a 'list' of data sources. Inside the list you might have multiple sources named, for example:

Then in each data source definition you have 'properties' which store the information you want to get to. In Java, Properties files don't have hierarchies like that, each key is unique and independent. You would have to build something that iterates all of the keys, parses them to their parts, and then builds a structure you can iterate over the way you want. I would imagine the need for a 'DataSource' class to hold the properties (jndi, user, password, etc...) then a Collection of some sort to hold the DataSource objects.

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38363
And welcome to the Ranch

I never thought there was anything suspicious about your displayed name.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38363
I think this thread is too difficult for "beginning Java", so I shall move it.
David C Shaw

Joined: Nov 05, 2010
Posts: 2
Thankyou sir! I am a beginner so I guess that's why I put the question in that section. Fingers crossed someone can give me a couple of pointers to set me on my way!

Steve, you are indeed correct. My build scripts basically have unique configuration code that looks at the props files, each individual resource (whether thats xa, an ear etc) has its own section and the scripts know the .'s separate different configurable values.

Thanks again!

Consider Paul's rocket mass heater.
subject: Reading multiple values from a properties file.