且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将ms word文档转换为二进制流(仅o和1),反之亦然.

更新时间: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 use FileStream 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);


问候