1. 写txt
FileStream F = new FileStream("sample.txt", FileMode.Open, FileAccess.Read, FileShare.Read); F.WriteLine("Hello"); F.Write("Hello"); F.Close();
2. 读写txt
using (StreamReader sr = new StreamReader(@"c:/jamaica.txt")) { string line; // 从文件读取并显示行,直到文件的末尾 while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); } }
参考:
http://www.runoob.com/csharp/csharp-file-io.html