title: Spring FileCopyUtils with strange behavior
body: <p>I don't know if anyone here uses <strong>FileCopyUtils</strong> offered by Spring framework, but I'm using a replication method of images in my system. It Aims to "catch" the images that are in the temp folder of my system and replicate to another folder on the server. Below is the method with some comments:</p>
  
  <pre><code>public Set&lt;Image&gt; imageReplication(String destination) throws IOException {
      Set&lt;Image&gt; img = new HashSet&lt;&gt;();
      Image image =null;
      try {
          List&lt;ImageJson&gt; imagePathTmpList = dashboardFacade.getImagePathTmpList();
  
          Gson gson = null;
  
          String subdomain = dashboardFacade.getAgency().getSubdomain();
          File base = new File("/home/manolo/joocebox-img/" + subdomain + "/"+ destination);
  
  
          for (ImageJson imageJsonList : imagePathTmpList) {
              gson = new Gson();
              image = new Image();
  
              FileMeta imgTmp = gson.fromJson(imageJsonList.getJson(), FileMeta.class);
              //File Old path
              String oldPath = imgTmp.getFileTmpPath();
  
              //New File Path
              String newPath = base + "/" + imgTmp.getFileName();
  
              //Checks if the base directory exists, if not it creates the path and makes copies of the files. I believe here that trigger the exeption.
              if(!base.exists()){
                  base.mkdirs();
                  FileCopyUtils.copy(new FileInputStream(oldPath), new FileOutputStream(newPath));
              }else{
                  FileCopyUtils.copy(new FileInputStream(oldPath), new FileOutputStream(newPath));
              }
  
              image.setJson(newPath);
              img.add(image);
  
          }
  
      } catch (FileNotFoundException e) {
          e.printStackTrace();
      }finally{
          deleteTmp();
      }
  
      return img;
  }
  </code></pre>
  
  <p>Well guys the problem is that at the time of checking if my way "base" exists in the server it is not created and is launching a FileNotFoundException exception. </p>
  
  <p>But strange that on my machine the behavior is normal. And only happens on my Amazon EC2 instance. </p>
  
  <p>I wonder if you agree with my logic and if I'm missing something.</p>
  
  <p>Best Regards</p>
  
  <hr>
  
  <p><strong>The stacktrace:</strong></p>
  
  <pre><code>java.io.FileNotFoundException: /home/ubuntu/joocebox-img/manolo/Test/MyImage.jpg (No such file or directory)
      at java.io.FileOutputStream.open(Native Method)
      at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:221)
      at java.io.FileOutputStream.&lt;init&gt;(FileOutputStream.java:110)
      at br.com.joocebox.controller.FileController.imageReplication(FileController.java:161)
      at br.com.joocebox.controller.FileController$$FastClassBySpringCGLIB$$282cc946.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
      at br.com.joocebox.controller.FileController$$EnhancerBySpringCGLIB$$e30b112a.imageReplication(&lt;generated&gt;)
      at br.com.joocebox.controller.DestinationController.addDestination(DestinationController.java:108)
      at br.com.joocebox.controller.DestinationController$$FastClassBySpringCGLIB$$49da9f7c.invoke(&lt;generated&gt;)
      at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
      at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:708)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:644)
      at br.com.joocebox.controller.DestinationController$$EnhancerBySpringCGLIB$$289546a0.addDestination(&lt;generated&gt;)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
      at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
      at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
      at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:646)
      at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
      at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>