using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace 文件流 { class Program { static void Main(string[] args) { //C#文件流写文件,默认追加FileMode.Append string msg = "ok"; byte[] myByte = System.Text.Encoding.UTF8.GetBytes(msg); using (FileStream fsWrite = new FileStream(@"C:\1.txt", FileMode.Append)) { fsWrite.Write(myByte, 0, myByte.Length); }; //c#文件流读文件 using (FileStream fsRead = new FileStream(@"C:\1.txt", FileMode.Open)) { int fsLen = (int)fsRead.Length; byte[] heByte = new byte[fsLen]; int r = fsRead.Read(heByte, 0, heByte.Length); string myStr = System.Text.Encoding.UTF8.GetString(heByte); Console.WriteLine(myStr); Console.ReadKey(); } } } }