title: Implement in command line using JAVA
body: <p>In my project, i need to segregate all .java files in a folder and paste it in a separate folder. I figured out that the below mentioned command works for this purpose</p>
  
  <pre><code>for /f "delims==" %k in ('dir C:\Project\downloads\*.java /s /b') do copy "%k" C:\Project\javaRepo
  </code></pre>
  
  <p>In the above command, the Source Folder : C:\Project\downloads\<br>
  Destination folder to copy all .java files : C:\Project\javaRepo</p>
  
  <p>I tried using the following command in JAVA,</p>
  
  <pre><code>Runtime rt = Runtime.getRuntime();
  Process proc = rt.exec(.....);
  </code></pre>
  
  <p>But I am not clear how to put the "for" command as an argument for rt.exec.  </p>
  
  <p>I tried creating a batch file as follows, but it doesn't work.</p>
  
  <pre><code>@echo off
  for /f "delims==" %k in ('dir C:\Project\downloads\*.java /s /b') do copy "%k" C:\Project\javaRepo
  </code></pre>
  
  <p>Can you let me know if my approach is correct, or is there any other better alternative?
  Suggestions / ideas are most welcome.</p>