我正在使用StreamWriter寫入文件。當我使用10-50個字的文字時,它可以正常工作。但是,當我再次調用該函數(超過50個字)時,它崩潰。這是爲什麼發生?有什麼建議麼?StreamWriter在C中與大文本文件崩潰#
這裏是代碼:
StreamWriter file = new StreamWriter("text6.txt");
file.Close();
int count = 0;
string temp = "";
string temp2 = "";
for (Match m = Regex.Match(str, qmatch2); m.Success; m = m.NextMatch())
{
temp = m.Value;
temp2 = Regex.Replace(temp, qmatch2, " . ");
str = Regex.Replace(str, temp, temp2);
}
if (temp.Contains(".") == false)
{
file = File.AppendText("text6.txt");
file.WriteLine(" " + temp);
count++;
file.Close();
}
您是否有能夠產生您所說的問題的代碼示例? –
您是否將StreamWriter包裝在try/catch塊中?拋出什麼異常? –
「超過50個單詞」 - 這不是'大' –