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

This is a viewer only at the moment see the article on how this works.

To update the preview hit Ctrl-Alt-R (or ⌘-Alt-R on Mac) or Enter to refresh. The Save icon lets you save the markdown file to disk

This is a preview from the server running through my markdig pipeline

Imported mostlylucidcouk

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

Sunday, 04 July 2004

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

logo

© 2025 Scott Galloway — Unlicense — All content and source code on this site is free to use, copy, modify, and sell.