Example & Tutorial understanding programming in easy ways.

What is difference between PrintWriter and ServletOutputStream?

For writing byte-oriented informations (such as image etc), we use ServletOutputStream class. It is a byte-stream class.

 On the other hand, PrintWriter class can only be used to write character based informations. It is a character-oriented class.

You may get the instance of ServletOutputStream class by calling the getOutputStream() method of ServletResponse interface. To get the instance of PrintWriter class you need to call the getWriter() method of ServletResponse interface.

Read More →