PrintWriter vs OutputStream
PrintWriter
Example:
PrintWriter writer = response. getWriter();
writer. println (“some text and HTML”);
Use it for:
Printing text data to a character stream.
Although you
can still write character data to an OutputStream, this
is the stream that’s designed to handle character data.
OutputStream
Example
ServletOutputStream out = response. getOutputStream();;
out. write (aByteArray);
Use it for:
Writing anything else!
Example:
PrintWriter writer = response. getWriter();
writer. println (“some text and HTML”);
Use it for:
Printing text data to a character stream.
Although you
can still write character data to an OutputStream, this
is the stream that’s designed to handle character data.
OutputStream
Example
ServletOutputStream out = response. getOutputStream();;
out. write (aByteArray);
Use it for:
Writing anything else!