PrintStream Class
Package: java.io
The PrintStream
class is similar to the PrintWriter
class in that it lets you write data to an output stream. PrintStream
and PrintWriter
have nearly identical methods. The primary difference is that PrintStream
writes raw bytes in the machine’s native character format, and PrintWriter
converts bytes to recognized encoding schemes. Thus, files created with PrintWriter
are more compatible across different platforms than files created with PrintStream
.
In general, you should use PrintWriter
rather than PrintStream
. However, the most common way to write console output — System.out
— uses PrintStream
to write data to the operator’s console. Using System.out
is the only time you should use PrintStream
instead of PrintWriter
. Because both classes provide the same methods, though, you probably won’t be aware of the difference when you use System.out
.
Constructors
Constructor |
Description |
|
Creates a print stream for the specified output stream. |
|
Creates a print stream for the specified output stream. If the second parameter is |
Methods
Method |
Description ... |
Get Java For Dummies Quick Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.