posted 15 years ago
Look closely at the JavaDocs. getRealPath will return null if the "file" isn't really a file. For example, when it's inside of a WAR file.
It's very bad practice to read or write to files inside the web application deployment. First, because they may not be files, as I just said. Secondly, because they can get accidentally wiped out when the application is updated.
If an app needs to write files, use an external directory (you can use JNDI to configure a path, if you'd rather not hard-code it in the app). If you need to read constant files and it's convenient to keep them as part of the deployed WAR, use the resource utilities to access the data.
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.