This works fine in a unit test. I get the file and can print the content. When I deploy this on a server I get a FilenotFoundExcpetion. What can be the reason for this? I am deploying on a tomcat.
String path = "WebContent/images/image.jpeg";
FileSystemResource resource = new FileSystemResource(path);
File image = resource.getFile();
this is a relative path, when deployed in a servlet container like tomcat it will be relative to your deployment directory or tomcat’s home directory. and probably you wont have a directory named Webconent. The contents of WebContent will perhaps be inside a war perhaps.
I can think of two solutions
getRealPathmethod if you have access torequestorServletContextClassPathResourceif you can put your file inWEB-INF\classes