Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.io.FileNotFoundException: (Access is denied)

807605Jun 24 2007 — edited Jun 25 2007
I try to upload an image to web server
but I become an java.io.FileNotFoundException: exception
what should be the problem ????
public void doUpload(HttpServletRequest request)
{
	  int MB = 2 * 1024 * 1024;
	  String fileName = "";
  	  String datei = request.getSession().getServletContext().getRealPath("/tmp");
	  DiskFileItemFactory factory = null;
	  factory = new DiskFileItemFactory();
      factory.setSizeThreshold(100*1024);
      factory.setRepository(new File(datei));
      
	  if(ServletFileUpload.isMultipartContent(request)){
		  File directory = new File(savePath);
          FileItem file = null;
          ServletFileUpload upload = new ServletFileUpload(factory);
          List items = null;
          if (directory.exists())
          {
        	 try
              {
                  items = upload.parseRequest(request);
                  Iterator iter = items.iterator();
                  while (iter.hasNext())
                  {
                      FileItem item = (FileItem)iter.next();
                      if (item.isFormField())
                      {
                          String name = item.getFieldName();
                          String value = item.getString();
                      }
                      else
                      {
                          file = item;
                          fileName = (new File(file.getName())).getName();
                          System.out.println("fileName: "+fileName);
                      }
                  }
                  File image = new File(savePath, fileName);
                  try
                  {
                      // error here
                      file.write(image);
                  }
                  catch (Exception e)
                  {
                      e.printStackTrace();
                  }
              }
              catch (FileUploadException fue)
              {
            	  fue.printStackTrace();
              }
          }else{
        	 
          }
      }else{}	
	
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 23 2007
Added on Jun 24 2007
19 comments
6,683 views