Name
PrintStream
Synopsis
This class is a byte output stream that
implements a number of methods for displaying
textual representations of
Java primitive data types.
System.out
and
System.err
are PrintStream
objects. PrintStream
converts characters to bytes
using the platform’s default charset, or the charset
or encoding named in the PrintStream( )
constructor invocation. In Java 5.0, convenience constructors allow
you to specify a file (either as a file name or a
File
object) as the destination of a
PrintStream
. Prior to Java 5.0 the destination had
to be another OutputStream
object.
The print( )
methods output standard textual representations of each data type.
The println( )
methods do the same and follow the representations with newlines.
Each method converts a Java primitive type to a
String
representation and outputs the resulting
string. When an Object
is passed to a
print( )
or println( )
, it is
converted to a String
by calling its
toString( )
method. In Java 5.0, you can also use the
printf( )
methods (or the format(
)
methods that behave identically) for formatted output. These methods
behave like the format( )
method of a
java.util.Formatter
object that uses the
PrintStream
as its destination.
This class implements the java.lang.Appendable
interface in
Java 5.0, which makes it suitable
for use with a java.util.Formatter
.
See also PrintWriter
for a character output stream
with similar functionality. And see
DataOutputStream
for a byte output stream that outputs binary, ...
Get Java in a Nutshell, 5th Edition 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.