C#里面,File.WriteAllText()的使用问题
来源:百度知道 编辑:UC知道 时间:2024/06/27 17:11:49
string htmltext = File.ReadAllText("D:/index/moban.htm");
System.IO.File.WriteAllText("D:/index/mx.htm", htmltext);
完成的目的是,把moban.htm里面的内容取出来,然后新建个mx.htm的页面,把先前的内容存到mx.htm当中
可为什么 生成了mx.htm,里面的中文都不见了?先前moban.htm里面的中文内容 为什么不能转存过来? 是我编码没调好么?
用了 GB2312 还有 UTF-8 都没用
怎么办?
System.IO.File.WriteAllText("D:/index/mx.htm", htmltext);
完成的目的是,把moban.htm里面的内容取出来,然后新建个mx.htm的页面,把先前的内容存到mx.htm当中
可为什么 生成了mx.htm,里面的中文都不见了?先前moban.htm里面的中文内容 为什么不能转存过来? 是我编码没调好么?
用了 GB2312 还有 UTF-8 都没用
怎么办?
应该是编码问题,如果网页用 GB2312 编码,则可以这么写:
htmltext = File.ReadAllText("D:/index/moban.htm", System.Text.Encoding.GetEncoding("GB2312"));
System.IO.File.WriteAllText("D:/index/mx.htm", htmltext, System.Text.Encoding.GetEncoding("GB2312"));
System.IO.File.WriteAllText("D:/index/mx.htm", Unicode2Ascii(htmltext),Encoding.ASCII);
试试看
C# Could not write to output file的问题
C#里面Console.Write与Console.WriteLine有什么区别????
C#里面,File.WriteAllText()的使用问题
为什么它总是输出“file write error”
虚拟光驱提示System file write error
Compiler Error Message: CS0016: Could not write to output file
daemon tool不能重新安装,报错system file write error
c# file.replace的小问题
C#中的Write和Writeline方法有什么不同啊
关于C#用Write()写入流的问题