Converting Byte Array to a File
Hi following is the two approaches for converting an existing byte array to the desired file in C# language.
Approach-1: Low-level coding
public void Convert()
{
FileStream stream = File.OpenRead(@"D:\youroutputfolder\filename.txt");
byte[] fileBytes= new byte[stream.Length];
stream.Read(fileBytes, 0, fileBytes.Length);
stream.Close();
using (Stream file = File.OpenWrite(@"c:\path\to\your\file\here.txt"))
{
file.Write(fileBytes, 0, fileBytes.Length);
}
}
Approach-2: Direct short cut
public void Convert(byte[] input)
{
File.WriteAllBytes(outputfileName, input);
}
There is not much to give an explanation for these approaches as those are well known.



