Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a binary file to a byte array?

Given the path of a file (e.g. "C:\MyPicture.jpg"), how do I convert a binary file into a byte array?

I know I have a lot of .NET objects at my disposal, such as BinaryReader, FileStream, StreamReader, and others, but I'm not sure of the best method to take a binary file and convert it into byte[]. How might this be accomplished?

like image 505
Ben McCormack Avatar asked Oct 11 '25 20:10

Ben McCormack


1 Answers

You're looking for File.ReadAllBytes(@"C:\MyPicture.jpg").

like image 168
SLaks Avatar answered Oct 14 '25 09:10

SLaks