How to write a byte array to a File in C# ?


This content was proof-read by Grammarly. You can Try Grammary for FREE

If you want to write a byte array to a file in C# , you can use the File.WriteAllBytes . Below is a code snippet demonstrating this.

How to write a byte array to a File in C# ?

using System;
using System.Collections.Generic;
using System.IO;

namespace ACCode
{
    class Program
    {
        static void Main(string[] args)
        {
            string pathOfFile = "test.txt";
            byte[] byteArray = GetByteArray();
            // Write the byte array to the file.
            File.WriteAllBytes(pathOfFile, byteArray);
            Console.ReadLine();
        }
        
    }
  
}
%d bloggers like this: