• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to Read XMl File From Java Code

 
sumeet gupta
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to read an xml file from my java code inside my web application. I m putting my xml file inside WEB-INF folder of my application. I am using following code to get xml file .

InputStream is = getClass().getResourceAsStream("/" + xmlfilename);

but its not getting xmlfile from this path and giving inputstream as null. Can anybody please help me out and tell me where should I put my xml file?


Thanks,
Sumeet Gupta
 
Muhammad Ijaz
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try getClass().getResourceAsStream("/WEB-INF/" + xmlfilename);
 
sumeet gupta
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Muhammad,

Thanks for your response,I tried with this option also even though its not working.

Thanks,
Sumeet Gupta
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getResourceAsStream uses the classloader to get the file, so any file must be in the classpath. In a web app this is anything in WEB-INF/classes or WEB-INF/lib. If your xml file were deployed in the root of the classes directory for example, your first bit of code should work.
 
sumeet gupta
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Paul....my error got resolved now...!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic