windows System.IO.File.ReadAllText 的默认编码是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6825601/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:35:59  来源:igfitidea点击:

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

windowsvb.netencodingscite

提问by Anonymous White

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 EXPLICITLYput System.Text.Encoding.Defaultbut things go wrong when I live that empty.

我不认为是System.Text.Encoding.Default。事情很好地工作,如果我明确标明System.Text.Encoding.Default但是出问题的时候,我住的是空的。

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?

如果我们不指定编码,vb.net 会尝试从文本文件中找出编码吗?

Also what is System.Text.Encoding.Default?

还有什么是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?

如果我创建一个新的文本文件并用 scite 打开它,我会看到编码是代码页属性。什么是代码页属性?

回答by TBohnen.jnr

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

这里,“此方法尝试根据字节顺序标记的存在自动检测文件的编码。可以检测编码格式 UTF-8 和 UTF-32(大端和小端)。”

回答by IlPADlI

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

另请参见http://msdn.microsoft.com/en-us/library/ms143375(v=vs.110).aspx此方法使用 UTF-8 编码,没有字节顺序标记 (BOM)