本文介绍了无法访问关闭的流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi Friends
我在MemoryStream中制作了一个XmlTextWriter
然后我要使用MemoryStream制作XmlDocument.
但是我收到了以下错误消息:无法访问关闭的流"
Hi Friends
I Made a XmlTextWriter in MemoryStream
Then I Want Make a XmlDocument Using MemoryStream.
But I Have Following a Error Message: "Cannot access a closed Stream"
XmlTextWriter xmlwr = new XmlTextWriter(MemoryStream,System.Text.Encoding.UTF8);
//Other Codes..
xmlwr.Close();
XmlDocument x = new XmlDocument();
x.Load(MemoryStream);
推荐答案
using(MemoryStream ms = new MemoryStream())
{
using(XmlTextWriter xmlwr = new XmlTextWriter(ms,System.Text.Encoding.UTF8))
{
//Other codes...
ms.Position = 0;//need to set the stream back to the start so it can be read
XmlDocument x = new XmlDocument();
x.Load(ms);
}
}
XmlDocument X=new XmlDocument()
x.Load(MemoryStream)
XmlTextWriter .Close()
这篇关于无法访问关闭的流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!