Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC:How to get file path into Controller?

I have following folder structure:

ProjectFolder/images/some images

In the same folder

ProjectFolder/WEB-INF/classes/com/xyz/here is java file of controller.

How can I get the image path in the controller?

Please, help. Thanks :)

like image 755
Sachin J Avatar asked Jan 19 '12 09:01

Sachin J


1 Answers

If its a web context may be something like this could help

InputStream is = null ;
is = request.getSession().getServletContext().getResourceAsStream("/images/someimage.jpg");

or may be something like this:

InputStream is = null ;
String realPath  = request.getSession().getServletContext().getRealPath("/images/someimage.jpg");
is = new FileInputStream(realPath);
like image 82
Moinul Hossain Avatar answered Sep 28 '22 04:09

Moinul Hossain