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
What's the default encoding for System.IO.File.ReadAllText
提问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
回答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)

