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

后端 未结 9 641
情深已故
情深已故 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:33

    The basic difference is that out.write() explodes if you pass it a null:

    String s = null;
    out.print(s); // outputs the text "null"
    out.write(s); // NullPointerException
    

提交回复
热议问题