title: Appending one text file to another in Java
body: <p>Good evening,</p>
  
  <p>I am entirely new to asking questions here, so sorry if I did this wrong.
  I am trying to append one whole .txt file to end of another one, on a new line,  without rewriting the contents.</p>
  
  <p>For example, I have this in one.txt</p>
  
  <pre><code>TEST 1 00001 BCOM
  </code></pre>
  
  <p>and I have this in two.txt,</p>
  
  <pre><code>TEST 2 00001 BCOM
  </code></pre>
  
  <p>This is the only working code I <strong>found</strong> that would copy/overwrite to another file,
  All others I've copied, reworked with file paths and names and tried and it doesn't work for me. I am still a beginner in Java.</p>
  
  <pre><code>import java.io.*;
  class CompileData {
      public static void main(String args[]) {
          FileReader fr = null;
          FileWriter fw = null;
          try {
              fr = new FileReader("one.txt");
              fw = new FileWriter("two.txt");
              int c = fr.read();
              while(c!=-1) {
                  fw.write(c);
                  c = fr.read();
              }
          } catch(IOException e) {
              e.printStackTrace();
          } finally {
              close(fr);
              close(fw);
          }
      }
      public static void close(Closeable stream) {
          try {
              if (stream != null) {
                  stream.close();
              }
          } catch(IOException e) {
          }
      }
  }
  </code></pre>
  
  <p>With this code, instead of getting this for two.txt</p>
  
  <pre><code>TEST 1 00001 BCOM
  TEST 2 00002 BCOM
  </code></pre>
  
  <p>I only get for two.txt</p>
  
  <pre><code>TEST 1 00001 BCOM
  </code></pre>
  
  <p>Any help, tips, pointers and answers will be gladly appreciated!</p>