Writing to console with System.out and PrintWriter

后端 未结 6 1906
独厮守ぢ
独厮守ぢ 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 02:52

    A quick Google revealed a thread on Coderanch which was useful.

    There are several other ways of doing console writing but there seems to be no real benefit of using one or the other apart from less code to write and that the creation of a new PrintWriter object will take up more memory (eventually).

    PrintWriter can write to other sources than just the console, it can write to an HttpResponse for example whilst System.out.println only writes to console.

提交回复
热议问题