I have created dynamic web project. In that I have written one Java class which opens a properties file and returns the value for a key passed to the function.
But to open the properties file I have to write a whole path like c:/Apache/webapps/webcontent/resources/system.properties. But I want to calculate the real path of this file using a relative path.
How to calculate the real path? This is not a servlet, it’s a complete Java file having only one class and its methods. How do I calculate the real path of a file?
If you load a
Filewith a relative path, callingFile.getCanonicalPath()orFile.getAbsolutePath()will give you the absolute path.When using an app server, your working directory will be where your app server was started from, so to get the absolute path to a
Fileusing a relative path, you would need to do: