- //写入文件
- public void WriteFile(string Content, string FileSavePath)
- {
- if(System.IO.File.Exists(FileSavePath))
- {
- System.IO.File.Delete(FileSavePath);
- }
- System.IO.FileStream fs = System.IO.File.Create(FileSavePath);
- Byte[] bContent = System.Text.Encoding.GetEncoding("gb2312").GetBytes(Content);
- fs.Write(bContent, 0,bContent.Length);
- fs.Close();
- fs = null;
- }
- //读取文件
- public string ReadFile(string FilePath)
- {
- System.IO.StreamReader rd = System.IO.File.OpenText(FilePath);
- string StrRead = rd.ReadToEnd().ToString();
- rd.Close();
- return StrRead;
- }
C#读写文件函数,解决写入乱码
最新推荐文章于 2023-05-18 16:54:00 发布