| Author |
Need to Read XMl File From Java Code
|
sumeet gupta
Ranch Hand
Joined: Aug 31, 2008
Posts: 33
|
|
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
Joined: Mar 03, 2009
Posts: 34
|
|
|
try getClass().getResourceAsStream("/WEB-INF/" + xmlfilename);
|
IBM Certified WebSphere Commerce Application Developer
|
 |
sumeet gupta
Ranch Hand
Joined: Aug 31, 2008
Posts: 33
|
|
Hi Muhammad,
Thanks for your response,I tried with this option also even though its not working.
Thanks,
Sumeet Gupta
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
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.
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
sumeet gupta
Ranch Hand
Joined: Aug 31, 2008
Posts: 33
|
|
Thanks Paul....my error got resolved now...!!
|
 |
 |
|
|
subject: Need to Read XMl File From Java Code
|
|
|