using(StreamWriter sw = File.CreateText(@"d:DefaultUTF8.txt"))
{
sw.Write("private");
}
using(StreamWriter sw=new StreamWriter(@"d:StreamUTF8.txt",
false,System.Text.Encoding.UTF8))
{
sw.Write("private");
}
using (System.IO.FileStream fs = System.IO.File.Create(@"d:ByteUTF8.txt"))
{
byte[] info = System.Text.Encoding.UTF8.GetBytes("private");
fs.Write(info, 0, info.Length);
}
I have always thought that the results of the above three methods are the same and there is no difference. Today I know that is not the case. Haha, if you think this question is naive, you don’t need to look down.
The results 1 and 3 are the same, both are E7. A7 81
And 2 will have an extra ZERO WIDTH NO-BREAK SPACE, which is EF BB BF
When we need to use Byte Order Mark to indicate the encoding method of the file, please use method 2. The
above is also applicable to UNICODE indicating Big-Endian and Little-Endian.
http://www.cnblogs.com/jjstar/archive/2006/12/18/595812.html