13,190
社区成员
发帖
与我相关
我的任务
分享
String ReadTxt,WriteTxt;
WriteTxt= String.Empty;
//if (!File.Exists(path))
//{
// using (StreamWriter streamwc = File.CreateText(path))
// {
// streamwc.Close();
// }
//}
//FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None);
//StreamWriter sw = new StreamWriter(path,false);
using (StreamReader sr = new StreamReader(path, System.Text.Encoding.Default))
{
ReadTxt = sr.ReadToEnd();
}
String[] FileRead = System.Text.RegularExpressions.Regex.Split(ReadTxt , "\r\n");
foreach(String ReadLine in FileRead)
{
if (ReadLine.Contains("="))
{
string subStr = ReadLine.Substring(0, ReadLine.LastIndexOf('='));
string keyStr = Key ;
if (subStr.Equals(keyStr))
{
WriteTxt += ReadLine.Substring(0, ReadLine.LastIndexOf('=')) +"="+value;
FileStream fs = new System.IO.FileStream(path,FileMode.Open, System.IO.FileAccess.Read, FileShare.ReadWrite);
using (StreamWriter streamw = new StreamWriter(fs))
{
streamw.WriteLine( WriteTxt);
fs.Close();
streamw.Flush();
streamw.Close();
}
//sw.Write(WriteTxt);
//sw.Dispose();
}
}
}