txt文件的讀寫
1.引用
using System.IO;
2.創(chuàng)建并寫
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; }

浙公網(wǎng)安備 33010602011771號