How to write a byte array to a file in c#

Thursday, 5 November 2009 12:04 by myro

An another piece of code that I should always remember...

public void writeByteArrayToFile(byte[] buff, string fileName)
{
 
     try
     {
               FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite);
               BinaryWriter bw = new BinaryWriter(fs);
               bw.Write(buff);
               bw.Close();

      }
      catch (Exception ex)
      {
              Console.WriteLine(ex.Message);
      }
}

Currently rated 4.3 by 6 people

  • Currently 4.333333/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:   .NET
Actions:   Bookmark and Share | Permalink | Comments (0) | Comment RSSRSS comment feed
If you consider this post usefull for your purposes, please consider visiting my sponsors to help me out with the myrocode.com maintenance. Thank you.