日期:2014-05-18 浏览次数:20494 次
StreamWriter sw = new StreamWriter("d:\\a.txt", false, System.Text.Encoding.Default); sw.Write("哈哈"); sw.Flush(); sw.Close();
------解决方案--------------------
要引入
//写入
using System.IO;
protect string file =@"C:\test.txt";
private void btnWriteFile_Click(object sender, System.EventArgs e)
{
if (File.Exists(file))
{
sw.WriteLine(“这是你要输入的汉字”);
sw.Close();
}
else
{
StreamWriter sr = File.CreateText(file);
sw.WriteLine(“这是你要输入的汉字”);
sr.Close();
sw.Close();
}
}
------解决方案--------------------
//写入
//要引入 以下命名空间
using System.IO;
protect const string file =@"C:\test.txt";
private void btnWriteFile_Click(object sender, System.EventArgs e)
{
if (File.Exists(file))
{
StreamWriter sw = new StreamWriter(file, false, Encoding.GetEncoding("gb2312"));//***
sw.WriteLine(“这是你要输入的汉字”);
sw.Close();
}
else
{
StreamWriter sr = File.CreateText(file);
StreamWriter sw = new StreamWriter(file, false, Encoding.GetEncoding("gb2312"));
sw.WriteLine(“这是你要输入的汉字”);
sw.Close();
}
}