Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Loading file from classes directory

 
Kalai Selvan
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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,
Kalai.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use ServletContext.getResource() or getResourceAsStream().
Give it a path relative to the root of your webapp.
IE:
getServletContext().getResourceAsStream("/WEB-INF/classes/myFile.xml");

http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getResourceAsStream(java.lang.String)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic