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

Anonymous White picture Anonymous White · Jul 26, 2011 · Viewed 11k times · Source

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 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?

Answer

TBohnen.jnr picture TBohnen.jnr · Jul 26, 2011

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."