I have a library that uses StreamWriter
to write a string into a Stream
. I need it to write that string into a NOT FILE stream like MemoryStream
. But when I try to read from that MemoryStream
using a StreamReader
I get an "Stream was not readable" error. Can anyone help?
The code is something like this:
var stream = new MemoryStream();
using (var sw = new StreamWriter(stream))
sw.Write("hello");
using (var sr = new StreamReader(stream))
MessageBox.Show(sr.ReadToEnd());
The library code is:
public void Save(Stream jsonStream)
{
if (jTokenValue == null)
{
return;
}
using (var streamWriter = new StreamWriter(jsonStream))
{
streamWriter.Write(jTokenValue.ToString());
}
}