Writing to console with System.out and PrintWriter

后端 未结 6 1905
独厮守ぢ
独厮守ぢ 2020-12-29 02:32

While reading about Java I/O, i realized that there are two ways through which i can write to the standard output.

Following is the snippet that uses both the techn

6条回答
  •  心在旅途
    2020-12-29 03:07

    Using PrintWriter makes the output internationalizable - because encodings like UTF-8 can be specified. Both PrintWriter and PrintStream classes should only be used for activities like console output - not for network programming - because of their platform-dependent treatment of line-breaks and swallowing of exception conditions. The second chapter of "Java Network Programming" has a good discussion on this.

提交回复
热议问题