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