// 创建要写入的文件 FileStream fs = File.Create( this .txtPath.Text); // byte[] content = new UTF8Encoding(true).GetBytes(this.textBox2.Text); // 创建byte数组,准备写入,将要写入的文本转成gb2312编码 byte [] content = Encoding.GetEncoding( " gb2312 " ).GetBytes( this .textBox2.Text); // 写入文件 fs.Write(content, 0 , content.Length); // 清除缓冲区,确定所有内容已被写入 fs.Flush();fs.Close(); 转载于:https://www.cnblogs.com/xsi640/articles/1015958.html