Timeline for StreamReader vs BinaryReader?
Current License: CC BY-SA 3.0
14 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Dec 10, 2014 at 9:24 | comment | added | Jon Skeet | @giorgim: Well that's why you can lose data. And fundamentally it's just a bad idea to treat data of one form as another - it encourages you to perform all kinds of inappropriate operations on it. | |
| Apr 27, 2012 at 16:31 | comment | added | Jon Skeet | @RoyiNamir: Unicode can represent almost any character you care to mention. But the key word here is character - not byte. Characters are for text. If you haven't got text, you haven't got characters. | |
| Apr 27, 2012 at 16:29 | comment | added | Royi Namir | @JonSkeet i got my problem. unicode is only for text. i thought it could also represent some ugly charcters . this was the source of my mistake. thanks. | |
| Apr 27, 2012 at 16:20 | vote | accept | Royi Namir | ||
| Apr 27, 2012 at 16:12 | comment | added | Jon Skeet | @RoyiNamir: Are you converting it into text in a naive way in both cases? If so, you're probably losing data in both cases, possibly consistently. Just don't do it - binary data isn't text, so don't try to pretend it is. If you really need to represent arbitrary binary data in text, use base64. | |
| Apr 27, 2012 at 16:10 | comment | added | Royi Namir | @jon ok ... one final thing : ive just read a jpeg file using binary reader -byte array size was 740. than i read via streamreader - to a string - string .length was still 740.... so...? | |
| Apr 27, 2012 at 16:07 | comment | added | Jon Skeet | @RoyiNamir: "Binary character" is a contradiction in terms. It's like talking about a "floating point integer". You must not read arbitrary binary data (e.g. a JPEG file) as text. You will lose information. | |
| Apr 27, 2012 at 16:06 | comment | added | Jon Skeet | @Nudier: No, neither StreamReader nor BinaryReader derive from Stream. There is absolutely a huge difference between using StreamReader and using BinaryReader. | |
| Apr 27, 2012 at 16:06 | comment | added | Royi Namir | @jon what im saying is that there isnt a binary charcter which i cant save it in string... so i can get the bin content to string via StreamReader and BinaryReader | |
| Apr 27, 2012 at 16:05 | comment | added | Nudier Mena | as you may know they all inherits from the base class stream, so there is no difference to use one of those. | |
| Apr 27, 2012 at 16:04 | comment | added | Jon Skeet | @RoyiNamir: No, a string is text. There's not even such a thing as a "UTF-8 string" - there's a UTF-8 binary representation of a string... A string holds text data - it's a sequence of characters. You then convert that to a binary representation using an encoding, such as UTF-8. Please read csharpindepth.com/Articles/General/Unicode.aspx | |
| Apr 27, 2012 at 16:04 | comment | added | Royi Namir | isnt a utf8 string can hold any info ? | |
| Apr 27, 2012 at 16:01 | comment | added | Royi Namir | but a utf8 string can contains inside it even binary data.. so... ? | |
| Apr 27, 2012 at 15:59 | history | answered | Jon Skeet | CC BY-SA 3.0 |