Reputation: 332
I am working with a servlet in Eclipse (Dynamic Web Project) . I have placed some image file in Web Content Folder with a sub-folder pics. Now there are images like pic1.jpg , etc.
BufferedInputStream bin = new BufferedInputStream(new FileInputStream(new File(location)));
What location should i give in order to retrieve these files?
Upvotes: 1
Views: 104
Reputation: 78
Try this
ServletContext ctx=getServletContext();
InputStream in = ctx.getResourceAsStream("/pics/pic1.jpg");
getResourceAsStream()
requires you to start with a "/"
which represents the root of the web app.
Upvotes: 2