title: How to use FileChannel to append one file's contents on to the end of another file?
body: <p>File <code>a.txt</code> looks like:</p>
  
  <pre><code>ABC
  </code></pre>
  
  <p>File <code>d.txt</code> looks like:</p>
  
  <pre><code>DEF
  </code></pre>
  
  <p>I'm trying to take "DEF" and append it to "ABC" so <code>a.txt</code> looks like</p>
  
  <pre><code>ABC
  DEF
  </code></pre>
  
  <p>The methods I've tried always completely overwrite the first entry so I always end up with:</p>
  
  <pre><code>DEF
  </code></pre>
  
  <p>Here are the two methods I've tried:</p>
  
  <pre><code>FileChannel src = new FileInputStream(dFilePath).getChannel(); 
  FileChannel dest = new FileOutputStream(aFilePath).getChannel();
  
  src.transferTo(dest.size(), src.size(), dest);
  </code></pre>
  
  <p>...and I've tried</p>
  
  <pre><code>FileChannel src = new FileInputStream(dFilePath).getChannel(); 
  FileChannel dest = new FileOutputStream(aFilePath).getChannel();
  
  dest.transferFrom(src, dest.size(), src.size());
  </code></pre>
  
  <p>The API is unclear about the transferTo and transferFrom param descriptions here:  </p>
  
  <p><a href="http://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html#transferTo(long" rel="noreferrer">http://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileChannel.html#transferTo(long</a>, long, java.nio.channels.WritableByteChannel)</p>
  
  <p>Thanks for any ideas.</p>