Win a copy of Mesos in Action this week in the Cloud/Virtualizaton 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: 20531
54
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: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic