title: FileStream.Read not reading last 'chunk'
body: <p>I have an interesting scenario I hope someone else has stumbled upon. I am attempting to copy part of an open FileStream to separate file streamin c# .Net 3.5. Using the code below, I read 37 'chunks' of 4096 bytes but <strong>fail to read the last 'partial chunk' of 3812 bytes</strong>. </p>
  
  <pre><code>string filPath = "c:\aRatherSmallFileThatCouldBeQuiteLarge.log";
  string tmpNam = Path.GetTempFileName();
  using (FileStream wt = new FileStream(tmpNam, FileMode.Open, FileAccess.Write))
  {
      using (FileStream rd = new FileStream(filPath, FileMode.Open, FileAccess.Read))
      {
          long cutPosition = 65217;
          int bytesRead;
          int chunkSize = 4096;
          byte[] buffer = new byte[chunkSize];
          while ((bytesRead = rd.Read(buffer, 0, chunkSize)) != 0)
              wt.Write(buffer, 0, bytesRead);
      }
      File.Copy(tmpNam, filPath, true);
  }
  File.Delete(tmpNam);
  </code></pre>
  
  <p>There are no errors produced; the final 3812 bytes are simply not written to the destination file as expected.</p>
  
  <p>It's a small example, but I'm intending to use this on very large files...so solutions that read the source file into memory are not viable here.</p>