------解决方案-------------------- using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO;
namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string csdn = "回帖是一种美德!每天回帖即可获得 10 分可用分!";
FileStream fs = new FileStream(@"d:\a.txt",FileMode.Append );//一定不要忘记@ 啊 StreamWriter sr = new StreamWriter(fs); sr.WriteLine(csdn); sr.Close(); fs.Close();
} } }
------解决方案--------------------
C# code
using System.IO;
namespace 将string变量保存到txt文档中
{
class Program
{
static void Main(string[] args)
{
string csdn="回帖是一种美德!每天回帖即可获得 10 分可用分!";
//使用Unicode编码,将csdn变量中的内容写到temp.txt文件中
StreamWriter sw = new StreamWriter("temp.txt", false, Encoding.Unicode);
sw.Write(csdn);
sw.Close();
Console.WriteLine("文件已经成功写入.");
Console.ReadLine();
}
}
}
------解决方案--------------------
C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (StreamWriter sw = new StreamWriter(@"c:\1.txt", true)) //存在C:\1.txt里面
{
string a = "i belive i can fly";
sw.Write(a);
sw.Flush();
}
}
}
}