• Post Reply Bookmark Topic Watch Topic
  • New Topic

Get path of file in java class in web application  RSS feed

 
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
Posts: 21135
87
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
Marshal
Posts: 56578
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!