9

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,017
  • 2
  • 20
  • 41
  • 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
  • @Hank, thanks for the tip. I'll give that a try. – ABC123 Jul 29 '14 at 15:10

2 Answers2

9

This should works:

test.folder=C:/code/

file=${test.folder}File.csv
matsjoyce
  • 5,503
  • 6
  • 30
  • 36
user4419622
  • 91
  • 1
  • 2
4

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
  • 910
  • 1
  • 8
  • 19