开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜