• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PrintWriter And ServletOutputStream API Doubt

 
Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Page-132 of HFSJ

println() to a PrintWriter
write() to a ServletOutputStream

BUT i have also seen a write() method on PrintWriter AND
i have also seen a println() method on ServletOutputStream
?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You usually use a PrintWriter to output text base documents, so println makes sense, whereas write does not. On the contrary, you usually use ServletOutputStream to output binary data where the carriage return does not make much sense. There are times when you'd like to mix both text and binary data (mulitpart response), where you can use ServletOutputStream#println. The authors want to focus on what we usually do, and on what is asked at the exam For the moment, just remember that you'll use PrintWriter to output text, and ServletOutputStream to output binary.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic