开发者

What's the default encoding for System.IO.File.ReadAllText

开发者 https://www.devze.com 2023-03-22 17:46 出处:网络
if we don\'t mention the decoding what decoding will they use? I do not think it\'s System.Text.Encoding.Default. Things work well if I EXPLICITLY put System.Text.Encoding.Default but things go wrong

if we don't mention the decoding what decoding will they use?

I do not think it's System.Text.Encoding.Default. Things work well if I EXPLICITLY put System.Text.Encoding.Default but things go wrong when I live that empty.

So this doesn't work well

Dim开发者_C百科 b = System.IO.File.ReadAllText("test.txt")
System.IO.File.WriteAllText("test4.txt", b)

but this works well

Dim b = System.IO.File.ReadAllText("test.txt", System.Text.Encoding.Default)
System.IO.File.WriteAllText("test4.txt", b, System.Text.Encoding.Default)

If we do not specify encoding will vb.net try to figure out the encoding from the text file?

Also what is System.Text.Encoding.Default?

It's the system default. What is my system default and how can I change it?

How do I know encoding used in a text file?

If I create a new text file and open it with scite I see that the encoding is code page property. What is code page property?


Look here, "This method attempts to automatically detect the encoding of a file based on the presence of byte order marks. Encoding formats UTF-8 and UTF-32 (both big-endian and little-endian) can be detected."


see also http://msdn.microsoft.com/en-us/library/ms143375(v=vs.110).aspx This method uses UTF-8 encoding without a Byte-Order Mark (BOM)

0

精彩评论

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