Writing bytes to a file in C#
<p>I have a BLOB from an Oracle database. In .NET it is of type OracleLob and has among them a Read and ReadByte methods.</p>

<pre><code>int OracleLob.Read(byte[] buffer, int offset, int count)
int OracleLob.ReadByte()
</code></pre>

<p>So the Read method reads a sequence of bytes and ReadByte reads a single byte at a time. Here is my code:</p>

<pre><code>OracleLob ol = (OracleLob) cmd.Parameters[1].Value; //her er filen!!

BinaryWriter binWriter = new BinaryWriter(File.Open(@"D:\wordfile.DOCX", FileMode.Create));
int currentByte = ol.ReadByte();

while (currentByte != -1)
{
   binWriter.Write(currentByte);
   currentByte = ol.ReadByte();
}

binWriter.Close();
</code></pre>

<p>But when I open wordfile.DOCX in Word, it says that the file is corrupt and cannot be opened. What am I doing wrong?</p>
