title: how to copy the contents of a last modified file from a folder to the other folder using java?
body: <p><em>i am trying  to copy the contents of a last modified file from a folder to the other folder using java</em></p>
  
  <p><em>i am able to move the file but i am unable to move the contents of the file</em></p>
  
  <pre><code>private File getLatestFilefromDir(String dirPath) throws IOException{
      File dir = new File(dirPath);
      File[] files = dir.listFiles();
      if (files == null || files.length == 0) {
      return null;
  }
  
  File lastModifiedFile = files[0];
  for (int i = 1; i &lt; files.length; i++) {
     if (lastModifiedFile.lastModified() &lt; files[i].lastModified()) {
         lastModifiedFile = files[i];
     }
  }
  String newFilePath = "C:\\newPath\\"+lastModifiedFile.getName();
  Path temp = Files.move 
          (Paths.get(dirPath), 
          Paths.get(newFilePath )); 
  
          if(temp != null) 
          { 
              System.out.println("File renamed and moved successfully"); 
          } 
          else
          { 
              System.out.println("Failed to move the file"); 
          } 
   return new File(newFilePath );
  }
  </code></pre>
  
  <p>Result : only file is moving but not contents</p>