Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 775
Anonymous White Avatar asked Jul 26 '11 05:07

Anonymous White


2 Answers

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

like image 157
TBohnen.jnr Avatar answered Dec 03 '22 19:12

TBohnen.jnr


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)

like image 24
IlPADlI Avatar answered Dec 03 '22 19:12

IlPADlI