What is the benefit of using a TextReader/Writer instead of a Binary Reader/Writer for string data?

StackOverflow https://stackoverflow.com/questions/22130669

Question

Is it correct to assume the only difference here is that Binary Reader/Writer use a fixed-length encoding for strings, and therefore may be less efficient?

No correct solution

OTHER TIPS

No there are a bucket load of other differences, e.g. read and writeline, encoding... Basically loads of 'helper' functions that pertain to text.

The difference is that regular text files aren't full of length prefixes. If you are writing a file that is intended to be read as text: use a TextWriter.

You might think that "ah, and BinaryWriter is for binary", but that isn't really true: BinaryWriter and BinaryReader are paired to eachother, but there is no "general" specification for writing text data in a binary file. It would entirely depend on the file format / protocol, and in most binary cases BinaryWriter is no use whatsoever. More commonly you just use Stream when dealing with binary data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top