title: Dart file copy in Windows
body: <p>The <code>File</code> class in the <code>dart:io</code> library doesn't yet include <code>copy()</code> and <code>move()</code> methods.</p>
  
  <p>To tide me over until they arrive, I'm trying to roll my own copy function.  I'm using the code below on Windows, but it just creates a 0kb file.</p>
  
  <pre class="lang-dart prettyprint-override"><code>void copyFile(String input, String output) {
    var inFile = new File(input), outFile = new File(output);
    if (outFile.existsSync()) outFile.deleteSync(); // I realize this isn't required
    var inStream = null, outStream = null;
    try {
      inStream = inFile.openInputStream();
      outStream = outFile.openOutputStream(FileMode.WRITE);
      inStream.pipe(outStream);
    } finally {
      if (outStream != null &amp;&amp; !outStream.closed) outStream.close();
      if (inStream != null &amp;&amp; !inStream.closed) inStream.close();
    }
  }
  </code></pre>
  
  <p>I've also tried replacing the <code>pipe</code> line with <code>print(inStream.read(100).toString());</code> and I get <code>null</code>.  The input file does exist (otherwise I'd get a FileIOException).  Am I doing something wrong, or are input streams broken under Windows?</p>
  
  <p>I'm using:</p>
  
  <ul>
  <li>Dart Editor version 0.3.1_r17463</li>
  <li>Dart SDK version 0.3.1.2_r17463</li>
  </ul>
  
  <p><strong>Edit:</strong> The following works (although it doesn't "chunk").  Am I using the streams above incorrectly?</p>
  
  <pre class="lang-dart prettyprint-override"><code>void copyFile(String input, String output) {
    var inFile = new File(input), outFile = new File(output);
    if (outFile.existsSync()) outFile.deleteSync(); // I realize this isn't required
    outFile.writeAsBytesSync(inFile.readAsBytesSync(), FileMode.WRITE);
  }
  </code></pre>