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

问题描述:

在我的项目中,我使用2个模块.一个用于编码器,另一个用于解码器.
编码器会将单词文件转换为二进制格式,而解码器将解码回原始格式.
这就是概念.

我正在使用Visual Studio 2010和WPF应用程序.

In my project I am using 2 modules. One for encoder and other one for decoder.
The encoder will convert the word file into binary form and decoder will decode back to original one.
This is the concept.

I am using Visual Studio 2010 and WPF application.

要读取字节文件,请使用以下代码:
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);


问候