title: Moving txt files to a folder instead of deleting them in java
body: <p>i have a code to concatenate txt files from a folder and move the concatenated file in another folder.
  My code is working well but it deletes files after concatenating them so i would like to move these files to another folder just after concatenating them.</p>
  
  <p>My files from c:\source must be moved to c:\Archive</p>
  
  <p>It was my mistake at the starting, i wanted to move files but i delete them!!
  And i would like to throw exception when there is no files in the source folder.</p>
  
  <p>So my code is:</p>
  
  <pre><code>PrintWriter pw = new PrintWriter(new FileOutputStream("C:/Target/Filec.txt"));// directory where concatenated file are created
  
      File file = new File("C:/Source");// where files have to be concatenated and move to c:\Archive before deleting
  
      File[] files2 = file.listFiles();
  
      for (int i = 0; i &lt; files2.length; i++)
      {
  
        File currentFile = files2[i];
  
        System.out.println("Processing " + currentFile.getPath() + "... ");
  
        BufferedReader br = new BufferedReader(new FileReader(currentFile));
  
        String line = br.readLine();
  
        while (line != null)
        {
          pw.println(line);
          line = br.readLine();
        }
        br.close();
        if (!currentFile.delete())
        {
          // Failed to delete file
          System.out.println("Failed to delete "+ currentFile.getName());
        }
      }
      pw.close();
      System.out.println("All files have been concatenated into Filec.txt");
      }
  }
  </code></pre>
  
  <p>Thank you</p>