# Another short one...how to read the contents of an entire file into a Byte Array...

<datetime class="hidden">2004-07-04T00:00</datetime>
<!-- category -- mostlylucidcouk, Imported -->

This just another one of thoise dumb little snippets that I always forget and is a bit of a bugger to find...so, if you for some reason (e.g., compression / encryption) need all of the contents of a file to be held in a byte array, here's the simplest way I've found to do it:

byte[] inArr;
using(Stream s=File.Open("myfile.dat",FileMode.Open))
{
inArr = new byte[s.Length];
s.Read(inArr,0,inArr.Length);
}