首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

无法写入已关闭的 TextWriter,该怎么解决

2012-02-27 
无法写入已关闭的 TextWriterSystem.ObjectDisposedException: 无法写入已关闭的 TextWriter连续创建2个文

无法写入已关闭的 TextWriter
System.ObjectDisposedException: 无法写入已关闭的 TextWriter
连续创建2个文本并且都写入数据。第二个出错。


[解决办法]
{
StreamWriter sr;
sr = File.CreateText(Request.PhysicalApplicationPath + "\\" + "1.txt");
sr.WriteLine("1");
sr.Close();
StreamWriter sw;
sw = File.CreateText(Request.PhysicalApplicationPath + "\\" + "2.txt");
sw .WriteLine("2");
sw .Close(); }


你上面的sr.Close();明显的关闭了,你后面还写当前出错了,改成上面的代码

[解决办法]
要不改成这样也可以,就不用第二个写文件的sw了


StreamWriter sr; 
sr = File.CreateText(Request.PhysicalApplicationPath + "\\" + "1.txt"); 
sr.WriteLine("1"); 
sr.Close();

sr= File.CreateText(Request.PhysicalApplicationPath + "\\" + "2.txt"); 
sr.WriteLine("2"); 
sr.Close(); }
[解决办法]
1.需要你贴下代码
2.估计问题是你还没有搞清楚引用类型的问题
[解决办法]

探讨
C# code {
StreamWriter sr;
sr = File.CreateText(Request.PhysicalApplicationPath + "\\" + "1.txt");
sr.WriteLine("1");
sr.Close();
StreamWriter sw;
sw = File.CreateText(Request.PhysicalApplicationPath + "\\" + "2.txt");
sr.WriteLine("2");
sr.Close();
}


就这个这个。。

热点排行