aspose file tools*
The moose likes Servlets and the fly likes saving a file to disk Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "saving a file to disk" Watch "saving a file to disk" New topic
Author

saving a file to disk

Ernesto Elias-Nieland
Ranch Hand

Joined: Sep 01, 2005
Posts: 53

Hi! I try to upload a file by a servlet and want to save it afterwards to disk. I'm using the org.apache.commons.fileupload package to get the file via a http post request. After that i want to create a new java.io.File object but get an IOException that says something like: "java.io.FileNotFoundException: C:\Programme\Apache Group\Tomcat 5.0\webapps\ROOT (access denied)"
The Tomcat is running on a windows xp system and i'm administrator on that machine. The folder in which i want to open the file is not write protected. Perhaps someone knows what i am doing wrong?
Here is my code:

@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

DiskFileUpload fu = new DiskFileUpload();
PrintWriter out = response.getWriter();

fu.setSizeThreshold(10000);
fu.setSizeMax(10000);
fu.setRepositoryPath("/.");

List fileItems = null;
try {
fileItems = fu.parseRequest(request);
out.print("Opening was succsessful!");
} catch (Exception ex) {
out.print("Opening was not succsessful!");
}

Iterator iter = fileItems.iterator();
FileItem item = (FileItem) iter.next();

File uploadedFile = new File(
"C:/Programme/Apache Group/Tomcat 5.0/webapps/ROOT");

try {
item.write(uploadedFile);
out.print("Saving was succsessful!");
} catch (Exception ex) {
out.print("Saving was not succsessful! \n");
out.print(ex.toString());
}
}


0x2B | ~0x2B
SCJD, SCJP 1.5, SCJP 1.4, SCBCD 1.3, SCWCD 1.4, SCJA, IBM Test 150, 142, 700, 701, Oracle Test 1Z0-51
Elihu Smails
Ranch Hand

Joined: Jan 12, 2005
Posts: 37
It might be due to the space in the pathname. I would not place spaces in pathnames or filenames if you want reliable functionality.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: saving a file to disk