Link to home
Start Free TrialLog in
Avatar of rahulkothari
rahulkothari

asked on

Cant read XML file

I have a XML file which i put in the WEB-INF/CLASSES folder , but when i run my code that tries to read this xml file , Here is the snippet of the code.
************************************************
Document doc = XMLUtil.getDocument(new InputSource((new Object()).getClass().getResourceAsStream("/" + "Trial.xml")));
*************************************************
, it always looks for the file in my c:\program files\apache group\Tomcat 4.1 directory.....ultimately i will be running all code on UNIX and i wont have access to directories outside my web-app , so how do i solve this issue ?? Please help
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rahulkothari
rahulkothari

ASKER

Nope doesnt work.....still looks in the same place
hmmm...

what about if you put it in the same directory as the class you are in, then do something like:

Document doc = XMLUtil.getDocument( new InputSource( getClass().getResourceAsStream( "Trial.xml" ) ) ) ;

?
>>Nope doesnt work.....still looks in the same place

How do you know where it's looking?
As TimYates mentioned, remove the "/", just use the file name.

Thanks
Amit
I guess putting it in the same directory as your classes is a simple way to do it.  I'd probably create a new folder under the WEB-INF folder (e.g. 'misc').  In the code, I'll call it this way:

Document doc = XMLUtil.getDocument( new InputSource( getClass().getResourceAsStream( "/misc/Trial.xml" ) ) ) ;
Correction:  It should have read:
Document doc = XMLUtil.getDocument( new InputSource( getClass().getResourceAsStream( "/WEB-INF/misc/Trial.xml" ) ) ) ;

The reason I'll create the misc folder is that I don't wanna mix up my .class files with other files.