In my Java
tomcat
application, I'm facing problems trying to get the correct file path.
Two code snippets from my Java app I need:
try {
InputStream in = getClass().getResourceAsStream("StaticContent/images/image.png");
image = ImageIO.read(in);
} catch (Exception e) {
System.out.print(e.getStackTrace());
}
Second snippet:
DataSource fds_image = new FileDataSource
("StaticContent/images/image.png");
I have put the image into the folder:
src/main/webapp/StaticContent/images/image.png
I have tried several ways to make sure the file path is correct, but nothing worked. Also, I put the image into the ressources folder and tried different paths but to no avail. I assume that I choose the wrong (relative) path, but I don't know how to handle it.
Can anybody help me with this?