title: Moving files to other folder based on the actual file name
body: <p>Moving files to other folder based on the actual file name</p>
  
  <p>Move a file from folder1 to other folder based on the file name </p>
  
  <p><strong>Example:</strong> </p>
  
  <p>Inside D drive: Folder called Tango has 3 files:</p>
  
  <pre><code>John1.txt
  John2.txt
  John3.txt
  </code></pre>
  
  <p>Inside D drive: There are 3 folders called:</p>
  
  <pre><code>John1
  John2
  John3
  </code></pre>
  
  <p>I would like to move the files from Tango folder to other folder(such as John1 or John2 or John3) based on match of file name with folder name.</p>
  
  <p>So far I was able to list the contents of folder, but I am not able to figure how to achieve the above.</p>
  
  <pre><code>public class FileCopy {
  
      public static void main(String[] args) {
  
          File f1 = new File("Tango");
          String[] allFiles = f1.list();
  
          for (String files : allFiles) {
              System.out.println(files);
          }
      }
  }
  </code></pre>