CryptoStream.Write()写入流时失败? [英] CryptoStream.Write() Failed while writing stream ??
问题描述
发生System.NotSupportedException
Message = Stream不支持编写.
来源= mscorlib
StackTrace:
在System.Security.Cryptography.CryptoStream.Write(Byte []缓冲区,Int32偏移量,Int32计数)
InnerException:
System.NotSupportedException occurred
Message=Stream does not support writing.
Source=mscorlib
StackTrace:
at System.Security.Cryptography.CryptoStream.Write(Byte[] buffer, Int32 offset, Int32 count)
InnerException:
请任何人帮助我
推荐答案
也许核心问题是底层流是关闭的.如果您在流的顶部创建一个新流,然后将其关闭,则默认情况下将关闭基础流.
maybe the core problem is, that the underlying stream is closed. If you create a new stream on top of a stream and then close it, then the underlying stream is closed by default.
因此,您有一个using块,其中有一个BinaryWriter(cout),并且在处置BInaryWriter时,流已关闭,因此您无法向其写入更多数据.
So you have a using block where you have a BinaryWriter(cout) and when the BInaryWriter is disposed, the stream is closed so you cannot write more data to it.
但是您可以高兴-BinaryWriter也有一个接受3个参数的构造函数,其中最后一个参数负责此行为:
http://msdn.microsoft.com/en-us/library/gg712841.aspx
But you can be happy - BinaryWriter also has an constructur which takes 3 arguments where the last argument is taking care of this behaviour:
http://msdn.microsoft.com/en-us/library/gg712841.aspx
也许您在其他流中遇到了类似的问题-不确定如何进一步使用该代码.但是,当处置cout时,基础流也将被关闭.
Maybe you run into similar issues with the other streams - not sure how the code is used further. But when cout is disposed, the underlying stream will be closed, too.
以诚挚的问候,
Konrad
这篇关于CryptoStream.Write()写入流时失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!