C# 写文件

来源:百度知道 编辑:UC知道 时间:2024/05/16 06:50:34
用c#读写文件,写成的文本用记事本打开全是乱码!!有什么方法吗?然后还要可以读出来,谢谢 ^ _ ^

你忘记Encoding了
FileStream fs = new FileStream(你的文件路径,FileMode.Open,FileAccess.Read);
StreamReader sr = new StreamReader(fs,Encoding.Default)//注意第二个参数
string 你要的字符串 = sr.ReadToEnd();

写文件同理啊
StreamWriter sw = new StreamWriter(你要保存的文件路径);
sw.Encoding = Encoding.Default;//指定编码格式
sw.Write();
sw.Close();//关闭
就可以了^_^