IO 101: Which are the main differences between TextWriter, FileStream and StreamWriter?

前端 未结 5 1605
悲哀的现实
悲哀的现实 2020-12-12 13:52

Let me first apologize if this question could sound perhaps sort of amateurish for the seasoned programmers among you, the thing is I\'ve been having many arguments about th

5条回答
  •  情书的邮戳
    2020-12-12 14:09

    The FileStream class manages getting a handle to a file and opening it for reading or writing and other filesystem functions. BinaryWriter writes binary data to a stream and StreamWriter writes character data to a stream. They both can use a FileStream object to write binary or character data to files.

    TextWriter is the base class that StreamWriter inherits from. A TextWriter is intended to take a type and output a string using its Write method. StreamWriter's implementation of the TextWriter.Write method writes a string, or character data, to a stream. BinaryWriter does not inherit TextWriter because it does not write character data to a stream.

提交回复
热议问题