• Post Reply Bookmark Topic Watch Topic
  • New Topic

PrintWriter vs PrintStream  RSS feed

 
Chris Wox
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I am very new to SCWCD and just started studying all by myself from K&b book. please forgive my dumb questions.

Could someone please explain difference between PrintWriter and PrintStream classes and can we use PrintStream class instead of PrintWriter
class , say , in the first example of k&b book as below ???

e.g
PrintWriter out = response.getWriter();
out.println ("<html>" + "<body>"+ "<h1 align=center>HF\'s Chapter1 Servlet </h1>" + "<br>" + today + "</body>" + "</html>");
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's a SCJP topic. Forget so soon?

From the API:
All characters printed by a PrintStream are converted into bytes using the platform's default character encoding. The PrintWriter class should be used in situations that require writing characters rather than bytes.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!