What is the Difference between PrintWriter and DataOutputStream?

后端 未结 3 960
天涯浪人
天涯浪人 2020-12-30 13:21

I\'m working on a chat room application for android. I read different tutorials; some of them use PrintWriter to send data and some of them use DataOutputStream. What is the

3条回答
  •  时光说笑
    2020-12-30 13:50

    From java docs

    A DataOutputStream lets an application write primitive Java data types to an output stream in a portable way. An application can then use a data input stream to read the data back in.

    PrintWriter Prints formatted representations of objects to a text-output stream. This class implements all of the print methods found in PrintStream. It does not contain methods for writing raw bytes, for which a program should use unencoded byte streams.

    In one sentence the difference is:

    OutputStreams are meant for binary data. Writers (including PrintWriter) are meant for text data

提交回复
热议问题