读:
var batFile = "D:\\test.bat"; if (File.Exists(batFile)) { using (var sr = new StreamReader(batFile)) { var content = sr.ReadToEnd(); } }
写:
var batFile = "D:\\test.bat"; using (var fs = new FileStream(batFile, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { using (var sw = new StreamWriter(fs)) { sw.WriteLine("Hello World"); } }