What is the Difference between PrintWriter and DataOutputStream?

后端 未结 3 1033
天涯浪人
天涯浪人 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:56

    Both DataOutputStream and PrintWriter are two classes in java.io.

    class DataOutputStream extends FilterOutputStream implements DataOutput {
    }
    

    Javadoc says

    "A data output stream 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."

     public class PrintWriter extends Writer {
     }
    

    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.

提交回复
热议问题