开发者

FileInfo.OpenRead() - what type of encoding does it use?

开发者 https://www.devze.com 2023-01-22 17:40 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消