actually reading again, should be: ...getRealPath("\WEB-INF\c
Main Topics
Browse All TopicsI want to load xml file from my web application. It is in:
C:\Documents and Settings\User\workspace\my
Now, I am using like this:
File indexfile = new File ("C:\\Documents and Settings\\User\\workspace\
But giving a path like that is not good, you know. So, I tried to call it by giving the path. I tried to use load-on-startup servlet, and call that 'realPath' variable from my JavaBean. See the code of the servlet please.
But that servlet, instead of giving the path to my application, it gives the path C:\Eclipse. So, I got the error like this:
java.io.FileNotFoundExcept
Any idea please. I have been trying this for quite long. And still got no solution.
I use Tomcat and Eclipse.
Really Thanks!!!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
> File indexfile = new File(index + "myIndex.xml");
you can't create a file from a url
> InputStream indexfile = getClass().getResourceAsSt
that should work, assuming its the right classloader. Is it returning null?
what container are you using?
> InputStream indexfile = loader.getResourceAsStream
should be /resources
> File resources = new File(MyServlet.realPath, "resources");
that should work, if you create realPath as I suggested in earlier post
> InputStream indexfile = getClass().getResourceAsSt
Yes, I got this error : java.lang.NullPointerExcep
> File resources = new File(MyServlet.realPath, "resources");
Please check the code snippet. I think it is what u said. But it returns: C:\Eclipse\.. not the real path.
I use Tomcat.
Yeah, sure there is directory 'resources' under WEB-INF/classes folder since I can call it using this: File indexfile = new File ("C:\\Documents and Settings\\User\\workspace\
And what you mean 'the exact set of conditions' ?
Thanks!!
>>And what you mean 'the exact set of conditions' ?
I just mean its being present all the time in all deployments
>>Yeah, sure there is directory 'resources' under WEB-INF/classes folder since I can call it using this
You should be able to get a url using the code i quoted normally. What happens? Please post result of
out.println(index);
> @ Object: So, is there noway to load an external files in web applications?
yes, but what you're trying to do is load a file internal to the webapp
> So, where exactly is the running webapp
In the directory I already posted earlier
> Where can I put those xml files to be seen and loaded using relative path from my web application?
put the resources folder in a source folder in your project
Sorry for my late response. I was on a trip so that I couldn't reply.
I got it. It only copies the files and folders under WebContent and just only the real classes folder under the WEB-INF\classes folder.
So, I move my resources folder under WebContent and so it copies it to \workspace\.metadata\.plug
And then I load the file using Servlet, what u described earlier.
Anyway, you guys helped me out a lot and I got to know that coz all of ur posts.
I really appreciate for that.
Thanks a lot!!
Business Accounts
Answer for Membership
by: objectsPosted on 2009-06-29 at 17:14:35ID: 24741281
> realPath = this.getServletContext().g etRealPath (".");
etRealPath ("/");
should be:
realPath = this.getServletContext().g