10

I have a properties file where I'd like to define a file path as a variable and then reference it. This is causing a file not found exception:

test.folder=C:/code/
file={test.folder}File.csv

But this works:

file=C:/code/File.csv

What am I doing wrong?

ABC123
  • 1,037
  • 2
  • 20
  • 44
  • variable substitution does not work in standard property files. You must implement this yourself or find a library doing this for you. see http://stackoverflow.com/questions/872272/how-to-reference-another-property-in-java-util-properties – Hank Lapidez Jul 28 '14 at 20:07

2 Answers2

11

This should works:

test.folder=C:/code/

file=${test.folder}File.csv
matsjoyce
  • 5,744
  • 6
  • 31
  • 38
user4419622
  • 111
  • 1
  • 3
5

In properties file i didn't think that you can concatenate the variable but you can do something like the following:

config.properties

test.folder=C:/code/
file=File.csv

Then in your java code concatenate two variable:

filePath = folder + file;

and if you are using spring xml file you can use:

<property name="filePath" value=${test.folder}${file} />
Saman Salehi
  • 1,004
  • 1
  • 12
  • 19