title: Copying the content of a list into a folder
body: <p>I have an arrayList &quot;rules&quot; containing Rules. Each Rule is an XML file and have some properties such as filename...</p>
  <p>I want to copy the Rules from the arraylist to a folder named AllMRG. I tried the code between comments but I get the message &quot;Source 'RG6.31.xml' does not exist&quot;.</p>
  <p>I changed the code by the following, but there is still a problem with 'RG6.31.xml' and the folder AllMRG is empty even though the arrayList contains many Rules!</p>
  <p>First attemption:</p>
  <pre><code>File AllMRGFolder = new File(&quot;AllMRG&quot;);
  for(int p = 0; p &lt; rules.size(); p++) {
      /* File MRGFile = new File(rules.get(p).fileName);  
      FileUtils.copyFileToDirectory(MRGFile, AllMRGFolder);  */
          
      File MRGFile = new File(&quot;AllMRG/&quot; + rules.get(p).fileName); 
      if (!MRGFile.exists()) {
          FileUtils.copyFileToDirectory(MRGFile, AllMRGFolder);
      }
  }
  </code></pre>
  <p>Second attemption:</p>
  <pre><code>String path = &quot;AllMRG&quot;;
          for(Rule rule : rules) {
              File MRGFile = new File(rule.fileName);
              Files.copy(MRGFile.toPath(), (new File(path + MRGFile.getName())).toPath(), StandardCopyOption.REPLACE_EXISTING);
          }
  </code></pre>
  <p>PS: Rule is a class</p>
  <pre><code>public class Rule implements Comparable{
  
      public String fileName;
      public String matches;
      public String TPinstances;
      public int nbrOfMatches;
      public double T;
  
      @Override
      public int compareTo(Object o) {
          if(o instanceof Rule){
              //processing to compare one Rule with another
          }
          return 0;
      }
  }
  </code></pre>
  <p>Here is the entire code after having considered Shyam's answer. The same problem persists!</p>
  <pre><code>Path directoryPath = Files.createDirectory(Paths.get(&quot;AllMGR&quot;));
          for(Rule rule : rules) {
              
              Path filePath = directoryPath.resolve(rule.fileName);
              Files.createFile(filePath);
       
              File MRGFile = new File(rule.fileName);
              String ruleContent = new String(Files.readAllBytes(Paths.get(MRGFile.getPath())));
              String fileContent = new String(Files.readAllBytes(filePath));  
              fileContent=ruleContent;
              PrintWriter out13= new PrintWriter(&quot;AllMGR/&quot;+rule.fileName+&quot;.xml&quot;);
              out13.print(fileContent);
              out13.close();
  } 
  </code></pre>