I get the following error:
java.nio.file.NoSuchFileException: \webapp\src\main\webapp\resources\pics\default.jpg
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
at sun.nio.fs.WindowsFileSystemProvider.newByteChannel(Unknown Source)
//it goes on and on
Anyways the exception seems to be caused when I create the new File
File fi = new File("/webapp/src/main/webapp/resources/pics/default.jpg");
byte[] fileContent = Files.readAllBytes(fi.toPath());
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_JPEG);
return new ResponseEntity<byte[]>(fileContent, headers, HttpStatus.OK);
I assume it's related to the image path but I tried several things and nothing worked. I'm using spring-mvc and here's how my folders look. default.jpg is located inside of pics and the code above is a portion of HelloWorldController
I was able to get images in my jsp files, but I assume its different here. I've seen other answers but I don't really know how to apply those solutions. Other answers suggest the use of InputStream but I don't think I can use that in this case.