This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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: 12759
    
    5
Look at the ServletContext getRealPath() method JavaDocs.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: create a file in the root directory
 
Similar Threads
Save a file on the application root
Saving file at server
Creating a JAR file contains TLD-file.
Simple Servlet Not Working
Directory Creation on FTP Server using Java Program