I'm using this method to write to a MemoryStream object, which is subsequen开发者_如何转开发tly stored a binary in SQL. It is being used to read in .HTML files from the file system on Windows.
How do I know which type of encoding this data is being read in as? Thanks.
None, because it opens a binary stream. When you e.g. wrap stream into a StreamReader
, that's the moment you choose the encoding. The FileStream
itself as returned by the OpenRead
method is not text based and thus does not have an encoding.
FileInfo.OpenRead
returns a raw stream that does not use any encoding (since it returns bytes, not characters).
Encodings are used to convert raw bytes into Unicode characters.
In .Net, encodings are used by the StreamReader
and StreamWriter
classes, which work with strings instead of bytes.
精彩评论