• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

saving a file to disk

 
Ranch Hand
Posts: 53
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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());
}
}
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic