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

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

    write() method only writes characters to stream(or console) but does not print, while print() method writes and print it on stream (or console).

    System.out.write(97);
    System.out.print('j');
    

    first statement writes character 97 i.e 'a' on console but does not print, while second statement prints 'a' which is written already on stream and 'j' which is passed in print() method.

提交回复
热议问题