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 ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access