老大好!
在使用System.IO.FileStream读取一个WORD文件时出现乱码!
System.IO.FileStream fs=File.OpenRead(MapPath("Cache/" + fileName + ".doc"));
byte[] fileB=new byte[fs.Length];
fs.Read(fileB,0,fileB.Length);
Encoding en=Encoding.GetEncoding("GB2312");
string file=en.getstring(fileB);file中是乱码StreamWriter sw=new StreamWriter(Server.MapPath("Cache/"+ fileName+"新的" + "."+dbType),false,System.Text.Encoding.GetEncoding("gb2312"));
sw.Write(file);
sw.Flush();
sw.Close();
同样,将这个file存为word文件,这个word文件中还是乱码!
请哪位老大指点,万分感激,
在使用System.IO.FileStream读取一个WORD文件时出现乱码!
System.IO.FileStream fs=File.OpenRead(MapPath("Cache/" + fileName + ".doc"));
byte[] fileB=new byte[fs.Length];
fs.Read(fileB,0,fileB.Length);
Encoding en=Encoding.GetEncoding("GB2312");
string file=en.getstring(fileB);file中是乱码StreamWriter sw=new StreamWriter(Server.MapPath("Cache/"+ fileName+"新的" + "."+dbType),false,System.Text.Encoding.GetEncoding("gb2312"));
sw.Write(file);
sw.Flush();
sw.Close();
同样,将这个file存为word文件,这个word文件中还是乱码!
请哪位老大指点,万分感激,
解决方案 »
- 为什么服务器上只有根目录有浏览ASPX网页,放在二级目录上就报错
- 怎么样用Dataset方法将数据库信息显示在DataGridView中?
- 诚心请教各位高手!怎样把数据发送到指定IP的终端?
- dataset Update的问题,SKS
- 数据库问题~~~
- c#里如何快速提取html里的文字?
- 比较大小,排序,出现的问题!
- 哪个兄弟能不能发给我一个在DataGrid中编辑,添加,删除数据的程序示例?(winform)
- 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作。
- 请进~ p指的是什么?
- 分享c#教学视频,准备学习或正在学习c#的请进!
- 关于PrintDocument中先预览再打印的的问题
StreamWriter fWrite = new StreamWriter((Stream)f,System.Text.Encoding.Unicode);
fWrite.Write(text);
fWrite.Flush();
fWrite.Close();
f.Close();如果不行就可能是语言问题,如果本地语言是汉语,就试试GBK编码
我的思路错误,也误导了大家,十分抱歉!
直接存byte即可,不能转为string,word格式转为string当然出乱码!
System.IO.FileStream fs=File.OpenRead(MapPath("Cache/" + fileName + ".doc"));
byte[] fileB=new byte[fs.Length];
fs.Read(fileB,0,fileB.Length); StreamWriter sw=new StreamWriter(Server.MapPath("Cache/"+ fileName+"新的" + "."+dbType),false,System.Text.Encoding.GetEncoding("gb2312"));
sw.Write(fileB);
sw.Flush();
sw.Close();