XmlSerializer Utf-8编码
考虑下面的代码
XmlSerializer serializer = new XmlSerializer(typeof(Invoice));
using (TextWriter writer = new StreamWriter(fileName))
{
// Serialize the object, and close the TextWriter.
serializer.Serialize(writer, invoice);
writer.Close();
}
默认情况下,流编写器上没有设置编码。如果您没有在流编写器上设置编码,它是否默认为 UTF-8?
Consider the code below
XmlSerializer serializer = new XmlSerializer(typeof(Invoice));
using (TextWriter writer = new StreamWriter(fileName))
{
// Serialize the object, and close the TextWriter.
serializer.Serialize(writer, invoice);
writer.Close();
}
No encoding is set on the stream writer by default. Does it default to UTF-8 if you don't set an encoding on the stream writer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,默认情况下,
StreamWriter
是为使用没有前导码的 UTF-8 而创建的。请参阅此处详细信息Yes, by default
StreamWriter
is created for using UTF-8 without preamble. See details here是的,StreamWriter 默认为 UTF-8,如此处所述
Yes, the StreamWriter does default to UTF-8 as mentioned here