namespace filetest { class FileUtil { public static void WriteFile(string file) { using (FileStream fs = new FileStream(file,FileMode.Append)) using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine("Hello,this is a StreamWriter test!"); } } public static void ReadFile(string file) { StringBuilder sb = new StringBuilder(); using(FileStream fs = new FileStream(file, FileMode.Open)) using(StreamReader sr = new StreamReader(fs)) { while (!sr.EndOfStream) { sb.Append(sr.ReadLine()); } } Console.WriteLine(sb.ToString()); } } }