title: SendFile and transferTo in Java
body: <p>I am using CentOs Kernel version 2.6.32.I plan to do a test with and without transferTo(sendFile) using NIO. My Test is to copy a 1GB file from one directory to another. However i didn't find any significant performance improvement because of using transferTo(). Please let me know if file to file sendFile really works in Linux kernel or only file to socket only works? Do I need to enable anything for sendFile?</p>
  
  <p>Sample code: </p>
  
  <pre><code>  private static void doCopyNIO(String inFile, String outFile) {
          FileInputStream fis = null;
          FileOutputStream fos = null;
          FileChannel cis = null;
          FileChannel cos = null;
  
          long len = 0, pos = 0;
  
          try {
              fis = new FileInputStream(inFile);
              cis = fis.getChannel();
              fos = new FileOutputStream(outFile);
              cos = fos.getChannel();
              len = cis.size();
              /*while (pos &lt; len) {
                  pos += cis.transferTo(pos, (1024 * 1024 * 10), cos);    // 10M
              }*/
              cis.transferTo(0, len, cos);
              fos.flush();
          } catch (Exception e) {
              e.printStackTrace();
          } 
  }
  </code></pre>