Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Servlets and the fly likes create a file in the root directory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "create a file in the root directory" Watch "create a file in the root directory" New topic
Author

create a file in the root directory

Praveen Sharma
Ranch Hand

Joined: Jul 31, 2008
Posts: 129
Hi,
based on some user action I need to create a file on the server inside the project's root directory. The url of my application is :
http://localhost:8080/Desk/Desk.html.

The name of the file is DeskItems.xml.

I tried to get the application Context path and appended that to the file name by using :
getServletContext.getPath("/") + "/DeskItems.xml";

But this approach is not working and I get an exception saying FileNotFound. I am using Tomcat server.

Please help me out in resolving this issue.


SCJP 80% SCWCD 89%
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12913
    
    5
Look at the ServletContext getRealPath() method JavaDocs.

Bill
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: create a file in the root directory