This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
An IDE is no substitute for an Intelligent Developer.