You cannot assume that the "current directory" (working directory) is reliable in a
J2EE environment.
The best way to maintain external content for a webapp is to create an external repository for it and configure the webapp to pull from it. For example, /var/lib/mywebapp/reports/pdf/.
You could hardcode such as location into the webapp, but I prefer something more flexibly, so I make it a JNDI variable defined in the webapp's web.xml. Here's a sample that defines a polling interval and its default value:
This value can then be retrieved by webapp code from the JNDI entry "java:comp/env/etc/pollinterval". A directory path would be the same way, except that you'd define the env-entry-type as a java.lang.String.
This is the default value, but many webapp servers can override it as part of the deployment process. For example, the
Tomcat webapp server's server-specific deployment descriptor is a Context definition, and the override would look like this:
And of course, since you're talking about file storage, I will add the usual warning: NEVER write files into a WAR. It's a violation of the J2EE standards, won't work on all servers or all configuations, and has a high risk of losing important data. The /var/lib location is a common Linux convention, but the actual place to generate or upload files isn't really important, just that it should be external to the WAR and to the webapp server.
Note that for
temporary files, you can use the java.io.File.mktmpfile() method to construct a temporary file and not have to know what directory the file is in, since the java.io.File element for the created file already knows it. In the case of Tomcat, the default location of that directory is in TOMCAT_HOME/temp, but it can be assigned anywhere. The webapp server is merely overriding the default JVM temp file directory location in any case.