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; }
标签:文件,string,FileStream,读写,sw,fs1,Close,new,txt From: https://www.cnblogs.com/RoilyaHazal/p/18048343