File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "create a file in the root directory" Watch "create a file in the root directory" New topic

create a file in the root directory

Praveen Sharma
Ranch Hand

Joined: Jul 31, 2008
Posts: 129
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 :

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

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

I agree. Here's the link:
subject: create a file in the root directory
It's not a secret anymore!