title: How to upload image file to spring mvc resource folder
body: <p>im working on a spring mvc project . i want to upload image and save it to resources/img/folder.</p>
  
  <p>I tried below code but it does not save the image to the directory.</p>
  
  <pre><code>@Autowired
      private HttpServletRequest request;
      try {
              // MultipartFile file = uploadItem.getFileData();
              String fileName = null;
              InputStream inputStream = null;
              OutputStream outputStream = null;
              if (multipartFile.getSize() &gt; 0) {
                  inputStream = multipartFile.getInputStream();
  
                  System.out.println("File Size:::" + multipartFile.getSize());
  
                  fileName = request.getSession().getServletContext().getRealPath("/resources/") + "/students/"
                          + multipartFile.getOriginalFilename();
                  outputStream = new FileOutputStream(fileName);
                  System.out.println("OriginalFilename:" + multipartFile.getOriginalFilename());
                  System.out.println("fileName----"+fileName);
                  int readBytes = 0;
                  byte[] buffer = new byte[10000];
                  while ((readBytes = inputStream.read(buffer, 0, 10000)) != -1) {
                      outputStream.write(buffer, 0, readBytes);
                  }
                  outputStream.close();
                  inputStream.close();
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  </code></pre>
  
  <p><strong>Exception</strong></p>
  
  <pre><code>11:00:39,436 INFO  [stdout] (http--0.0.0.0-8080-5) File Size:::7346
  11:00:39,436 ERROR [stderr] (http--0.0.0.0-8080-5) java.io.FileNotFoundException
  : C:\jboss-as-7.1.1.Final\standalone\tmp\vfs\deployment65ea7dd580659db3\ObviousR
  esponseWeb-1.2-SNAPSHOT.war-3a7509e73dad1cba\resources\students\zzzz.jpg (The sy
  stem cannot find the path specified)
  </code></pre>