• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1739
  • Last Modified:

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
0
rahulkothari
Asked:
rahulkothari
1 Solution
 
TimYatesCommented:
Can't you do:

Document doc = XMLUtil.getDocument(new InputSource( getClass().getResourceAsStream( "/" + "Trial.xml" ) ) ) ;
0
 
rahulkothariAuthor Commented:
Nope doesnt work.....still looks in the same place
0
 
TimYatesCommented:
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" ) ) ) ;

?
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
CEHJCommented:
>>Nope doesnt work.....still looks in the same place

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

Thanks
Amit
0
 
anthony_castillonCommented:
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" ) ) ) ;
0
 
anthony_castillonCommented:
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.

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now