File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Groovy and the fly likes Gstring interpolation from properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Gstring interpolation from properties file" Watch "Gstring interpolation from properties file" New topic

Gstring interpolation from properties file

Jon Walser

Joined: Jul 23, 2012
Posts: 6
I've been handed a piece of groovy code and tasked with making it work. Of course it "worked fine" in its original environment...or so I'm told.

Properties file:


properties = new Properties();
FileInputStream propFile = new FileInputStream(

String dbEnv = properties.getProperty("db.db", "");
String url = properties.getProperty(dbEnv + ".jdbc.url", "");

System.out.println("env:" + dbEnv);
System.out.println("url:" + url);


And an error indicating that my url value didn't work.
I've read about the use of Gstring interpolation, but I don't see how to apply it in a properties file. I can, of course, write some method to walk through the properties, but I'm hoping for a more elegant solution.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

Can you change the properties file or does the code have to work with that specifically?

GenRocket - Experts at Building Test Data
Jon Walser

Joined: Jul 23, 2012
Posts: 6
The properties file is hundreds of lines long and will necessarily grow when the interpolation references are expanded. This will require significant manual effort, with the associated risk of fat-fingering and will increase the future maintenance issues.

I am already creating a simplyfied properties file (one database, one environment etc) so I can test the rest of the program. I was just hoping for a more elegant way.
I agree. Here's the link:
subject: Gstring interpolation from properties file
It's not a secret anymore!