What is the advantage over the PrintWriter System.out?

Give an example to demonstrate the superiority character stream PrintWriter on the standard flow System.out?
July 2nd 19 at 14:00
1 answer
July 2nd 19 at 14:02
Compare warm with soft, PrintWriter is the class and System#out object.
But the difference between byte and character streams tell you in any decent book/course.

UPD so the difference between PrintWriter and PrintStream
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.

Unlike the PrintStream class, if automatic flushing is enabled it will be done only when one of the println, printf, or format methods is invoked, rather than whenever a newline character happens to be output. These methods use the platform''s own notion of line separator rather than the newline character.

  • PrintStream uses platform encoding by default (now it does not seem so, in 1.4 and 1.5 added several constructors that accept one of the options encoding).
  • The PrintWriter should be used in situations that require writing characters rather than bytes. Despite this type of field System#out are unlikely to change, backward compatibility, after all.
  • If enabled autoflush PrintWriter does flush only when caused by one of the print methods.
  • It seems PrintWriter uses the line separator of the platform and not always the new line character (\n).
Show the difference and the advantages of special, I do not see. Whether to create an application using standard output System.out, or is it worth to create a separate object of PrintWriter? - mathias.Mayert commented on July 2nd 19 at 14:05
the book of shilda just written that instead of the standard flow System.out better to use a stream PrintWriter, PrintWriter is better and why - not says. Maybe I missed something. - mathias.Mayert commented on July 2nd 19 at 14:08
: it only remains to add that in large applications typically use their own loggers, and not just stdout. - charity84 commented on July 2nd 19 at 14:11

Find more questions by tags Java