Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get path of file in java class in web application

 
rajnish chattha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50224
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic