Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

saving a file to disk

 
Ernesto Elias-Nieland
Ranch Hand
Posts: 53
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
}
}
 
Elihu Smails
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be due to the space in the pathname. I would not place spaces in pathnames or filenames if you want reliable functionality.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic