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

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

문제

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 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top