Home > DeveloperSection > Interviews > What is difference between PrintWriter and ServletOutputStream?

Posted on    November-03-2014 11:11 PM

 Java OOPS 
 1 Answer(s)
  1362  View(s)
Rate this:

Kamlakar Singh
Kamlakar Singh

Total Post:80

Posted on    November-04-2014 12:11 AM

PrintWriter is a character-stream class whereas ServletOutputStream is a byte-stream class. We can use PrintWriter to write character based information such as character array and String to the response whereas we can use ServletOutputStream to write byte array data to the response.

We can use ServletResponse getWriter() to get the PrintWriter instance whereas we can use ServletResponse getOutputStream() method to get the ServletOutputStream object reference.

Don't want to miss updates? Please click the below button!

Follow MindStick