mostlylucid

scott galloway's personal blog...
posts - 911, comments - 723, trackbacks - 11

My Links

News

Archives

Post Categories

Misc. Coding

Another short one...how to read the contents of an entire file into a Byte Array...

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);
}

Print | posted on Tuesday, February 24, 2004 5:06 PM | Filed Under [ .NET Code Snippets ]

Comments have been closed on this topic.

Powered by: