wood burning stoves 2.0*
The moose likes Servlets and the fly likes Create directories while uploading files in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Create directories while uploading files in Servlet" Watch "Create directories while uploading files in Servlet" New topic
Author

Create directories while uploading files in Servlet

Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
Hi!

I am required to upload files using my web application. Using a servlet for this. And using Apache Commons - FileUpload (My favourite is the O' Reilly Multipart, but cant use it because of licensing issues).

Problem:

The file upload works fine as long as i try to upload to directories already present, but if the directories are not present and i try to create the directories, i get an 'Access Denied' Exception.

Here is the code:



and the Exception is:



Yep, i know, not the best of codes, but am concerned with the Exception at the moment.

Should i separate the tasks of making the directories and then writing to them in 2 different servlets? Will that work??
[ October 06, 2005: Message edited by: Neeraj Dheer ]
Neeraj Dheer
Ranch Hand

Joined: Mar 30, 2005
Posts: 225
sorry...my mistake...bug in the code...was trying to open a directory with FileOutputStream, not a file...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Create directories while uploading files in Servlet