Java Reference
In-Depth Information
tem.out . If an argument is not a primitive type, the PrintWriter methods will call the ob-
ject's toString( ) method and then print out the result.
To write to the console using a PrintWriter , specify System.out for the output stream
and flush the stream after each call to println( ) . For example, this line of code creates a
PrintWriter that is connected to console output.
The following application illustrates using a PrintWriter to handle console output.
The output from this program is
Remember that there is nothing wrong with using System.out to write simple text output
to the console when you are learning Java or debugging your programs. However, using
a PrintWriter will make your real-world applications easier to internationalize. Since no
advantage is to be gained by using a PrintWriter in the sample programs shown in this
book, for convenience we will continue to use System.out to write to the console.
Search WWH ::




Custom Search