开发者

Reading/writing POP3 data

I'm receiving data from POP3 server and initially i used StreamWriter to write the data(as text) to a file on the disk, but with this approach certain characters ca开发者_开发问答nnot be decoded. Everything is ok if i use BinaryWriter and the BinaryWriter.Write(Byte[]) method. As far as i know StreamWriter writes text characters using specified encoding(certain bytes can be modified throughout the process), and BinaryWriter writes the original bytes to the file, is that right?


If you've got bytes to start with and want to transfer them to a file, I'd suggest not using either BinaryWriter or StreamWriter - just use a Stream (e.g. FileStream). BinaryWriter is useful when you want to write primitives etc to a stream - but if you just want to dump a sequence of bytes, Stream does everything you want. You certainly shouldn't use StreamWriter to transfer opaque binary content; treat text as text, and binary data as binary data, and only translate between the two when you're sure of what you're doing (e.g. that the binary data is actually text in a particular encoding).


can you show us how you are opening the StreamWriter specifying the encoding. I believe you should use the proper encoding in there, the one you are using now is probably wrong.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜