File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Loading file from classes directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Loading file from classes directory" Watch "Loading file from classes directory" New topic

Loading file from classes directory

Kalai Selvan
Ranch Hand

Joined: Jul 07, 2004
Posts: 79
I am having a helper class which is used by servlet. Now i am trying to load a xml file in my applications WEB-INF/classes dir by only giving the file name (since it is directly under classes folder). but it is referring to c:/documents and settings/userhome dir. can any one tell me how to get the xml file from classes directory.

Thanks and Regards,
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

You can use ServletContext.getResource() or getResourceAsStream().
Give it a path relative to the root of your webapp.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: Loading file from classes directory
It's not a secret anymore!