1

I'm trying to save files to my folder 'ProfileImages' which resides in WebContent/

When I run with below path I'm getting file not found exception

String appPath = request.getServletContext().getRealPath("/");

String savePath = appPath + "WebContent" + File.separator + "ProfileImages";

System.out.println(appPath + "WebContent" + File.separator + "ProfileImages");

print gives:

C:\Users\me\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Test\WebContent\ProfileImages\image.jpg (path not found)
JonCode
  • 241
  • 1
  • 8
  • 20

1 Answers1

1

There is no need to put "WebContent" folder in save path since , passing the "/" to getRealPath() would return you the absolute disk file system path of the /web folder of the expanded WAR file of the project

String savePath = appPath +  File.separator + "ProfileImages";

See also

What does servletcontext.getRealPath(“/”) mean and when should I use it

Community
  • 1
  • 1
rupesh_padhye
  • 1,355
  • 2
  • 13
  • 25
  • Thanks, I'll just stick to using absolute path when testing. But it worked when I deploy it as war. – JonCode Oct 22 '15 at 16:58