StreamWriter中的BUG [英] BUG in StreamWriter

查看:61
本文介绍了StreamWriter中的BUG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




使用以下内容构造StreamWriter时..

FileStream f = new FileStream(..);

StreamWriter s = new StreamWriter(f);


然后尝试写出???他们变成了垃圾信件。


但是如果我们按如下方式调用StreamWriter ...

FileStream f =新的FileStream(..);

StreamWriter s = new StreamWriter(f,System.Text.Encoding.Default);


没问题。那么为什么默认不是真正的DEFAULT,就像它在ctor上说的那样?


在我看来,ctor是错的还是名字。默认是误导性的。


谢谢。

Hi,

When constructing StreamWriter with the following..
FileStream f = new FileStream(..);
StreamWriter s = new StreamWriter(f);

Then attempt to write out ??? letters they become garbage.

BUT

If we call StreamWriter as follows...
FileStream f = new FileStream(..);
StreamWriter s = new StreamWriter(f, System.Text.Encoding.Default);

Its ok. So why is default not the actual DEFAULT as it says on the ctor?

It seems to me either the ctor is wrong or the name .Default is misleading.

Thanks.

推荐答案

< di ******** @ discussion.microsoft.com>写道:
<di********@discussion.microsoft.com> wrote:

使用以下内容构造StreamWriter时...
FileStream f = new FileStream(..);
StreamWriter s = new StreamWriter(f);

然后尝试写出来???他们变成了垃圾。

如果我们按如下方式调用StreamWriter ...
FileStream f = new FileStream(..);
StreamWriter s = new StreamWriter(f,System.Text.Encoding.Default);

没关系。那么为什么默认值不是真正的DEFAULT,就像它在ctor上所说的那样?

在我看来,ctor是错的还是名字。默认是误导。

When constructing StreamWriter with the following..
FileStream f = new FileStream(..);
StreamWriter s = new StreamWriter(f);

Then attempt to write out ??? letters they become garbage.

BUT

If we call StreamWriter as follows...
FileStream f = new FileStream(..);
StreamWriter s = new StreamWriter(f, System.Text.Encoding.Default);

Its ok. So why is default not the actual DEFAULT as it says on the ctor?

It seems to me either the ctor is wrong or the name .Default is misleading.




..默认是*略有误导,虽然所有信息都在

文档中。新StreamWriter(Stream)的文档说:


< quote>

这个构造函数创建一个带UTF-8编码的StreamWriter,其

GetPreamble方法返回一个空字节数组。 BaseStream属性

使用stream参数初始化。

< / quote>


然而,简要说明它使用默认和默认。编码

有误导性(我会给MS发邮件)。


..默认意味着默认*平台*编码 - 但几乎是

默认情况下.NET中的所有内容都使用UTF-8。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



..Default is *slightly* misleading, although all the information is in
the documentation. The docs for new StreamWriter(Stream) say:

<quote>
This constructor creates a StreamWriter with UTF-8 encoding whose
GetPreamble method returns an empty byte array. The BaseStream property
is initialized using the stream parameter.
</quote>

However, the brief summary saying that it uses "the default" encoding
is misleading (I''ll mail MS about it).

..Default means the default *platform* encoding - but pretty much
everything in .NET itself uses UTF-8 by default.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


所以UTF8无法处理变音符号然后

" Jon Skeet [C#MVP]" < SK *** @ pobox.com>在消息中写道

新闻:MP ************************ @ msnews.microsoft.c om ...

< di ******** @ discussion.microsoft.com>写道:
So UTF8 cant handle umlaut characters it seems then
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<di********@discussion.microsoft.com> wrote:

使用以下内容构造StreamWriter时...
FileStream f = new FileStream(..);
StreamWriter s = new StreamWriter(f);

然后尝试写出来???他们变成了垃圾。

如果我们按如下方式调用StreamWriter ...
FileStream f = new FileStream(..);
StreamWriter s = new StreamWriter(f,System.Text.Encoding.Default);

没关系。那么为什么默认值不是真正的DEFAULT,就像它在ctor上所说的那样?

在我看来,ctor是错的还是名字。默认是

When constructing StreamWriter with the following..
FileStream f = new FileStream(..);
StreamWriter s = new StreamWriter(f);

Then attempt to write out ??? letters they become garbage.

BUT

If we call StreamWriter as follows...
FileStream f = new FileStream(..);
StreamWriter s = new StreamWriter(f, System.Text.Encoding.Default);

Its ok. So why is default not the actual DEFAULT as it says on the ctor?

It seems to me either the ctor is wrong or the name .Default is



误导。


..默认有点*误导,虽然所有信息都在

的文档中。新StreamWriter(Stream)的文档说:


< quote>

这个构造函数创建一个带UTF-8编码的StreamWriter,其

GetPreamble方法返回一个空字节数组。 BaseStream属性

使用stream参数初始化。

< / quote>


然而,简要说明它使用默认和默认。编码

有误导性(我会给MS发邮件)。


..默认意味着默认*平台*编码 - 但几乎是

默认情况下.NET中的所有内容都使用UTF-8。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件


misleading.

..Default is *slightly* misleading, although all the information is in
the documentation. The docs for new StreamWriter(Stream) say:

<quote>
This constructor creates a StreamWriter with UTF-8 encoding whose
GetPreamble method returns an empty byte array. The BaseStream property
is initialized using the stream parameter.
</quote>

However, the brief summary saying that it uses "the default" encoding
is misleading (I''ll mail MS about it).

..Default means the default *platform* encoding - but pretty much
everything in .NET itself uses UTF-8 by default.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


< di ******** @ discussion.microsoft.com>写道:
<di********@discussion.microsoft.com> wrote:
所以UTF8无法处理变音符号然后
So UTF8 cant handle umlaut characters it seems then




是的它可以。只是无论你用什么来阅读文件

大概都不知道它是用UTF-8编码的。


- -

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复群组,请不要给我发邮件



Yes it can. It''s just that whatever you were using to read the file
presumably wasn''t aware that it was encoded in UTF-8.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


这篇关于StreamWriter中的BUG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆