title: Append Byte Array at the End of an File
body: <p>I would like to append an Byte Array to an existing File. It <strong>must</strong> be at the end of the File. I could already manage to write at the start of the file. (Thanks to stackoverflow ;)).</p>
  
  <p>Code for that:</p>
  
  <pre><code>public bool ByteArrayToFile(string _FileName, byte[] _ByteArray)
  {
     try
     {
        // Open file for reading
        System.IO.FileStream _FileStream = 
           new System.IO.FileStream(_FileName, System.IO.FileMode.Create,
                                    System.IO.FileAccess.Write);
    // Writes a block of bytes to this stream using data from
    // a byte array.
    _FileStream.Write(_ByteArray, 0, _ByteArray.Length);
  
    // close file stream
    _FileStream.Close();
  
    return true;
     }
  catch (Exception _Exception)
  {
    // Error
    Console.WriteLine("Exception caught in process: {0}",
                      _Exception.ToString());
  }
  
  // error occured, return false
  return false;
  </code></pre>
  
  <p>}</p>
  
  <p>Got it from here:</p>
  
  <p><a href="https://stackoverflow.com/questions/6397235/write-bytes-to-file">Link</a></p>
  
  <p>But I need it at the end of the file</p>
  
  <p>Thanks in advance.</p>
  
  <p>Found the solution:</p>
  
  <pre><code>FileStream writeStream;
          try
          {
              writeStream = new FileStream(_FileName, FileMode.Append,FileAccess.Write);
              BinaryWriter writeBinay = new BinaryWriter(writeStream);
              writeBinay.Write(_ByteArray);
              writeBinay.Close();
          }
          catch (Exception ex)
          {
              Console.WriteLine(ex.ToString());
          }
  </code></pre>