title: Struts2 file upload and save
body: <p>I have successfully uploaded a file in Struts2 with the following code:</p>
  
  <pre><code>String filePath = servletRequest.getSession().getServletContext().getRealPath("/") + "WEB-INF\\files\\";
              fileToCreate = new File(filePath, getUserDocFileName());
  
              FileUtils.copyFile(this.userDoc, fileToCreate);
  </code></pre>
  
  <p>The problem is that the file gets copied to the \build\web\WEB-INF\files folder. Now, when I try to retrieve the file using result type stream:</p>
  
  <pre><code>String filePath = servletRequest.getSession().getServletContext().getRealPath("/") + "WEB-INF\\files\\";
  File file = new File(filePath + getFileName());
              try {
                  inputStream = new DataInputStream(new FileInputStream(file));
              } catch (FileNotFoundException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
  
  
  &lt;action name="loadFile" class="com.app.Controller" method="loadFile"&gt;
              &lt;result name="success" type="stream"&gt;
                  &lt;param name="contentType"&gt;${fileType}&lt;/param&gt;
                  &lt;param name="inputName"&gt;inputStream&lt;/param&gt;
                  &lt;param name="contentDisposition"&gt;inline;filename="${fileName}"&lt;/param&gt;
                  &lt;param name="bufferSize"&gt;1024&lt;/param&gt;
              &lt;/result&gt;
              &lt;interceptor-ref name="defaultStack"/&gt;
          &lt;/action&gt;
  </code></pre>
  
  <p>I get the following exception:</p>
  
  <pre><code>java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [inputStream] in the invocation stack. Check the &lt;param name="inputName"&gt; tag specified for this action.
  </code></pre>
  
  <p>Any help regarding this problem? </p>
  
  <p>Is <code>FileUtils.copyFile</code> approach same as setting <code>struts.multipart.saveDir</code> property?</p>
  
  <p>How can I place the file in the WEB-INF folder but not in the build folder?</p>
  
  <p>The files should not get deleted whenever I build my project again. I want to deploy it to OpenShift later on.</p>