read from file in c#
The code
FileStream fs = new FileStream(fileName, FileMode.Open)
fs.ReadByte()
will read 开发者_JAVA百科a byte from the file, what should I do to read 2 bytes at a time ?
Allocate a 2-byte array and pass that as argument to the FileStream.Read function.
byte[] twoBytes = new byte[2];
int bytesRead = fs.Read(twoBytes, 0, twoBytes.Length);
Wrap the call up in a loop and read into a datastructure eg. byte[] ?
Use the 'normal' read method. Use the parameters to define the number of bytes you want to read.
精彩评论