Maneesh Godbole wrote:Whenever a method is deprecated, most of the times they suggest a work around. Did you check the API docs for suggested alternatives?
?
The API does not say it is depreciated. So can i use that code ?? Please explain me in details the path that i need to give within the getReaPath() ..
1. The HttpServletRequest.getRealPath() is deprecated, you can use the ServletContext.getRealPath() method as a replacement. It stated in the javadoc if you've read it.
2. Your app should be deployed in exploded mode, when you deploy the webapp in war format the getRealPaht() method return null.
3. When you creating multiple directory use File.mkdirs() instead of File.mkdir().
1. The HttpServletRequest.getRealPath() is deprecated, you can use the ServletContext.getRealPath() method as a replacement. It stated in the javadoc if you've read it.
2. Your app should be deployed in exploded mode, when you deploy the webapp in war format the getRealPaht() method return null.
3. When you creating multiple directory use File.mkdirs() instead of File.mkdir().
Hope this can help you.
Thank You for your suggestion Wayan.. But can you help me with the code for this ? I mean how should i use the ServletContext.getRealPath() method ? Give an example if possible.
How should you use it? Well, you shouldn't use it. Creating files inside your web application is a bad idea.
If they are meant to be permanent files, then don't put them in your web app, because they will disappear as soon as you redeploy it. Put them somewhere else.
And if they are meant to be temporary files, then Java already has a system property ("java.io.tmpdir") which contains the name of its temporary-file directory. Put them there.