2

I have two files (one .properties and another .json) in my webapps//WEB-INF/classes folder. I need to reference the .json file from the .properties file. As both are in same location, propertyName=File.json should work,but it does not. If I mention the absolute path, it works fine.

Please suggest.

Anushree Acharjee
  • 854
  • 5
  • 15
  • 30

1 Answers1

0

What you should do is read your File.json exactly the same way as your properties file if you don't want to specify the absolute path. If propertyName=File.json :

String jsonFile = props.getProperty("propertyName");

Then you can do the following to have your file as URL object :

URL jsonURL = Thread.currentThread().getContextClassLoader().getResource(jsonFile);

Or as InputStream

InputStream jsonStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(jsonFile);

Depending on what you want to do with it later, once you have your file as InputStream or URL, you can refer to these questions :

Community
  • 1
  • 1
Fab
  • 893
  • 1
  • 13
  • 22