title: Output stream writing more that read - C#
body: <p>I am having a brain-dead moment, staring blankly at this little section of code for 10 mins now... can someone please tell me why the output file (test2.txt) contains more text that the file it is reading from (test.txt) ??</p>
  
  <p>Here is teh code:</p>
  
  <pre><code>FileStream inputStream = new FileStream(@"C:\Temp\test.txt", FileMode.Open);
  FileStream outputStream = new FileStream(@"C:\Temp\test2.txt", FileMode.OpenOrCreate);
  byte[] buffer = new byte[1024];
  
  Console.WriteLine(new FileInfo(@"C:\Temp\test.txt").Length + "\n");
  
  while (inputStream.Read(buffer, 0, buffer.Length) &gt; 0)
  {
        Console.WriteLine("bufferlength " + buffer.Where(x =&gt; x != 0).ToArray().Length);
        Console.WriteLine(new FileInfo(@"C:\Temp\test2.txt").Length);
        outputStream.Write(buffer, 0, buffer.Length);
        outputStream.Flush();
        Console.ReadKey();
  }
  
  Console.WriteLine("\n" + inputStream.Length);
  Console.WriteLine(outputStream.Length);
  Console.Read();
  </code></pre>
  
  <p>Thanks guys</p>