This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Servlets and the fly likes Reading file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Reading file" Watch "Reading file" New topic

Reading file

Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
I want to read an XMl file that is placed somewhere in the web-root/WEB-INF/ folder in the deployed war on the server.
How can I read the file from here by dynamically getting the complete file path??
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 12982
Look at the api for the javax.servlet.ServletContext interface.
With a ServletContext there are several possibilities - getResourceAsStream is popular or you can getRealPath to get an absolute path String.
Monmohan Singh
Ranch Hand

Joined: Aug 02, 2002
Posts: 82
thanks a lot for the help
It is sorta covered in the JavaRanch Style Guide.
subject: Reading file
It's not a secret anymore!