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().getRe sourceAsSt ream("/" + "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
**************************
Document doc = XMLUtil.getDocument(new InputSource((new Object()).getClass().getRe
**************************
, 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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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().getResourceAsSt ream( "Trial.xml" ) ) ) ;
?
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().getResourceAsSt
?
>>Nope doesnt work.....still looks in the same place
How do you know where it's looking?
How do you know where it's looking?
As TimYates mentioned, remove the "/", just use the file name.
Thanks
Amit
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().getResourceAsSt ream( "/misc/Trial.xml" ) ) ) ;
Document doc = XMLUtil.getDocument( new InputSource( getClass().getResourceAsSt
Correction: It should have read:
Document doc = XMLUtil.getDocument( new InputSource( getClass().getResourceAsSt ream( "/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.
Document doc = XMLUtil.getDocument( new InputSource( getClass().getResourceAsSt
The reason I'll create the misc folder is that I don't wanna mix up my .class files with other files.
ASKER