streamwriter对已存在文件读写
using (StreamReader sr = File.OpenText(tbPath.Text))
{
using (StreamWriter sw = File.CreateText(path))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
strInCode = s;
if (strInCode.IndexOf(strBReplace) > -1)
{
s = strInCode.Replace(strBReplace,strAReplace);
sw.WriteLine(s.Trim());
}
else
{
sw.WriteLine(s.Trim());
}
}
}
}
if(File.Exists(path))
{
ProcessStartInfo psi = new ProcessStartInfo(path);
Process p = new Process();
p.StartInfo = psi;
p.Start();
}
主要功能要实现文件中字符串b置换成字符串a
如果读取的文件是已经存在的就会出文件不让访问的错误,
如果这样就是不让写的话,新建一个文件能覆盖原来的文件吗?