Friday, February 4, 2011

FileInfo Get File Bytes

1. approach

FileStream fs = myfileInfo.OpenRead();
int bytesCount =(int)fs.Length;
byte[] bytes = new byte[bytesCount];
int bytesRead = fs.Read(bytes, 0, bytesCount);
fs.Close();

2. approach

byte[] bytes = System.IO.File.ReadAllBytes(myfileInfo.FullName);

1 comment:

Leo Reading said...

I always forget about the File.ReadAllBytes method. Thanks for posting this!