我正在尝试将文本写入我的 txt 文件。第一次写入后应用程序崩溃并出现错误
无法写入已关闭的 TextWriter
我的列表包含浏览器打开的链接,我想将它们全部保存在 txt 文件中(如日志)。
我的代码:
FileStream fs = new FileStream(
"c:\\linksLog.txt", FileMode.Append, FileAccess.Write);
StreamWriter sw = new StreamWriter(fs);
for (int i = 0; i < linksList.Count; i++)
{
try
{
System.Diagnostics.Process.Start(browserType, linksList[i]);
}
catch (Exception) { }
using (sw)
{
sw.WriteLine(linksList[i]);
sw.Close();
}
Thread.Sleep((int)delayTime);
if (!cbNewtab.Checked)
{
try
{
foreach (Process process in Process.GetProcesses())
{
if (process.ProcessName == getProcesses)
{
process.Kill();
}
}
}
catch (Exception) { }
}
}