Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cant read XML file

Posted on 2003-11-24
7
Medium Priority
?
1,732 Views
Last Modified: 2006-11-17
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
Comment
Question by:rahulkothari
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 500 total points
ID: 9811801
Can't you do:

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

Author Comment

by:rahulkothari
ID: 9811998
Nope doesnt work.....still looks in the same place
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9812009
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 9812211
>>Nope doesnt work.....still looks in the same place

How do you know where it's looking?
0
 
LVL 2

Expert Comment

by:amit_chauhan
ID: 9812406
As TimYates mentioned, remove the "/", just use the file name.

Thanks
Amit
0
 
LVL 2

Expert Comment

by:anthony_castillon
ID: 9813973
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
 
LVL 2

Expert Comment

by:anthony_castillon
ID: 9813989
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question