C#:对txt文件的读写
File.WriteAllLines(Application.StartupPath + @"\班级.txt", banji, Encoding.UTF8);//将所有行数据写进数组里面 class = File.ReadAllLines(Application.StartupPath + @"\班级.txt");//将数组里面的数据写进文件
名称空间:
using System.IO;
新建一个txt文件
string path = "g:/txt/" + str + ".txt"; using (StreamWriter sw = new StreamWriter(path, true, Encoding.Unicode)) { sw.Write("测试"); }
对txt文件的追加
StreamWriter sw = File.AppendText("g:\\Text.txt"); sw.WriteLine(kvp.Value); sw.Close();