C# 读写bat文件

读:

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");
    }
}

 

posted @ 2018-05-10 11:01  ㄌㄟ  阅读(712)  评论(0编辑  收藏  举报