更新时间:2022-12-07 17:27:43
要读取字节文件,请使用以下代码:
To read a file in bytes use the following code :
byte[] bytes = File.ReadAllBytes("filename.ext");
现在,您可以对字节数组进行任何操作.
Now you can do what ever you want to the array of bytes.
为了读取字节,可以使用FileStream
class.
Hi,
In order to read the bytes you can useFileStream
class.
FileStream stream = new FileStream("pathtodoc.ext", FileMode.Open);
byte [] array = new byte[stream.Length];
int bytesread = stream.Read(array, 0, stream.Length);
为了将字节写回到流中,请使用Write
方法.
In order to write back the bytes into stream use Write
method.
FileStream stream = new FileStream("pathtodoc.ext", FileMode.Create);
stream.Write(array, 0, stream.Length);
问候