首页 > 代码库 > c#读写txt文件

c#读写txt文件

//表示清空 txt
StreamWriter sw = new StreamWriter("D:\\1.txt");
string w = "";
sw.Write(w);
sw.Close();
//表示向txt写入文本
StreamWriter sw = new StreamWriter("D:\\1.txt");
string w = "10";
sw.Write(w);
sw.Close();
//表示追加文本
StreamWriter sw =File.AppendText("D:\\1.txt");
string w = "2";
sw.Write(w);
       //sw.WriteLine(w);
       sw.Close();

c#读写txt文件