如何将ms word文档转换为二进制流(仅o和1),反之亦然. [英] how to convert the ms word document into binary stream(only o's & 1's) and viceversa..

查看:396
本文介绍了如何将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);


问候


这篇关于如何将ms word文档转换为二进制流(仅o和1),反之亦然.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆