Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

PrintWriter and OutputStream

 
parra matta
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

On page 132 in HFJS, it says that for ServletOutputStream use write() and for PrintWriter use println().

However ServletOutputStream has lots of method print or println and PrintWriter has lots of methd write. and Acutally I can use println for ServletOutputStream and write for PrintWriter.

Is the book wrong?
 
Akshay Kiran
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can use any method you want,
but to make the most out of efficiency,
use the write method of ServletOutputStream
and print, println of PrintWriter
(because PrintWriter is specially made for character and text based output while the regular outputstream is used for writing out other forms of data like binary etc.)
which is exactly what the book recommends you to do
 
parra matta
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Akshay.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!