4

I'm trying to make it so that in config/app.properties, I can have:

myfile.location=./myfile

where . is relative to said properties file. Is this possible ? I tried:

resourceLoader.getResource(appConfig.getMyFileLocation());

where resourceLoader and appConfig are autowired, but it won't work.

Vinz243
  • 9,654
  • 10
  • 42
  • 86

2 Answers2

1

I usually reference my files like this:

myfile.location=classpath:myfile

where myfile is at the same location as the properties file.

StrongPoint
  • 331
  • 1
  • 5
0

Java properties are key-value pairs. So when you specify myfile.location=./myfile, this means appConfig.getMyFileLocation() will return './myfile' which is not the correct location.

As a workaround, you can get the location of the properties file and then use it along with the relative location to find the absolute path.

File propertyFileDirectory = .... // get the property file directory
String myfilePath = appConfig.getMyFileLocation();
File file = new File(propertyFileDirectory, myfilePath);
Arpit Sharma
  • 900
  • 5
  • 11