loading a file to an array in 8 bit pieces

  • Thread starter Thread starter Flemming Hansen
  • Start date Start date
F

Flemming Hansen

Hi guys,

I want to load a binary file in to an array by splitting the file in 8 bit
pieces. I mean:

FileStream s = new FileStream(path, FileMode.OpenOrCreate); // Open

StreamReader r = new StreamReader(s);

string data = r.ReadToEnd();

r.Close();

the file is loaded to the string "data" as a long string, and I want to
split "data" in 8 bit pieces and save it in an array

what's the easiest way of doing it?
 
Flemming Hansen said:
I want to load a binary file in to an array by splitting the file in 8 bit
pieces. I mean:

FileStream s = new FileStream(path, FileMode.OpenOrCreate); // Open

StreamReader r = new StreamReader(s);

string data = r.ReadToEnd();

r.Close();

the file is loaded to the string "data" as a long string, and I want to
split "data" in 8 bit pieces and save it in an array

what's the easiest way of doing it?

Do you really mean 8 bit pieces, i.e. bytes? If so, just use Stream and
read from it. See http://www.pobox.com/~skeet/csharp/readbinary.html
for a way to reliably read the entire contents of a stream.
 
Back
Top