This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Get path of file in java class in web application Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Get path of file in java class in web application" Watch "Get path of file in java class in web application" New topic
Author

Get path of file in java class in web application

rajnish chattha
Greenhorn

Joined: Dec 01, 2011
Posts: 3
HI am quite new to java programming and till now I am doing XSLT transformation on static location files

File xmlFile = new File("D://Dashboard.xml");

File xsltFile = new File("D://Dashboard.xslt");
But ,now i have kept these 2 files into path
WebContent/XML/Dashboard.xml
WebContent/XSLTL/Dashboard.xml

When i run my project it says file cannot found.
Kindly tell how do I get the actual path of these files so that at run time it picks the file from root directory and perform some operations.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Check out ServletContext and its getRealPath method. That takes a path relative to the web application's root folder, and turns it into an absolute path.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
And welcome to the Ranch
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Get path of file in java class in web application
 
Similar Threads
Ant javac task error with Rational application developement studio 7
jasper in a WebApp
How to write dynamic images to web server?
ContextPath Query
root.getRootElement() is throwing an NullPointerException