以下代碼從一個數組中讀取一個文件(一次一個)到一個字符串中,替換字符串中的匹配模式,然後將其附加到文件中。C#StreamWriter問題
我希望它覆蓋,而不是追加。我在這裏做錯了什麼?
using (FileStream fs = new FileStream(fileList[i], FileMode.Open))
using (StreamReader fileIn = new StreamReader(fs, true))
{
String file = fileIn.ReadToEnd().ToLower();
MessageBox.Show(file);
if (file.Contains(oPath))
{
updated++;
file = file.Replace(oPath, nPath);
using (StreamWriter replaceString = new StreamWriter(fs, Encoding.Unicode))
{
replaceString.Write(file);
listBoxResults.Items.Add(fileList[i]);
}
}
}
完美,謝謝:] – cc0 2010-12-07 13:34:41