4

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?

Ben McCormack
  • 32,086
  • 48
  • 148
  • 223

2 Answers2

8

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

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
6
byte[] bytes = File.ReadAllBytes("C:\\MyPicture.jpg");
Philippe Leybaert
  • 168,566
  • 31
  • 210
  • 223