txt文件的读写
1.引用
using System.IO;
2.创建并写
public void WriteTxt(string filepth, string str) { FileStream fs1 = new FileStream(filepth, FileMode.Create, FileAccess.ReadWrite); StreamWriter sw = new StreamWriter(fs1); sw.WriteLine(str); sw.Close(); fs1.Close(); }
3.读
public string ReadTxt(string filepath) { FileStream fs1 = new FileStream(filepath, FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs1); var line = sr.ReadLine(); sr.Close(); fs1.Close(); return line; }

浙公网安备 33010602011771号