How to convert a Stream to a String

  • Thread starter Thread starter ad
  • Start date Start date
A

ad

I have a Steam, it read from a text file.
How can I convert this Stream to a String?
 
What kind of stream? You should be able to use a StreamReader to get
the contents of the stream.
 
ad said:
I have a Steam, it read from a text file.
How can I convert this Stream to a String?

Is StreamReader.ReadToEnd() what you are looking for?
 
ad said:
I have a Steam, it read from a text file.
How can I convert this Stream to a String?

The easiest way is skip the stream and just do File.ReadAllText().

Alternatively, if you must use the stream, then do:

---8<---
new StreamReader(stream).ReadToEnd()
--->8---

-- Barry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top