What is the exact difference between out.write() and out.print()

后端 未结 9 629
情深已故
情深已故 2020-12-13 20:49

In my servlet I gave both out.print and out.write. but both prints in the browser.

What is the exact difference between these two and when

9条回答
  •  星月不相逢
    2020-12-13 21:46

    PrintWriter:

    public void write(String s)

    Write a string. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.

    print method has higher level of abstraction.

    public void print(String s)

    Print a string. If the argument is null then the string "null" is printed. Otherwise, the string's characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.

    Hope this helps.

提交回复
热议问题