How can I get real path for file in my WebContent folder?

newbie picture newbie · May 7, 2010 · Viewed 63.1k times · Source

I need to get real path for file in my WebContent directory, so that framework that I use can access that file. It only takes String file as attribute, so I need to get the real path to this file in WebContent directory.

I use Spring Framework, so solution should be possible to make in Spring.

Answer

Shyam picture Shyam · May 7, 2010

If you need this in a servlet then use getServletContext().getRealPath("/filepathInContext")!