开发者

read from file in c#

开发者 https://www.devze.com 2023-03-04 03:05 出处:网络
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

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

精彩评论

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