Java Reference
In-Depth Information
char
int
float
Object
boolean
char[]
long
double
String
These methods are much more convenient than the raw stream
write
methods. For example, given a
float
variable
f
and a
PrintStream
refer-
ence
out
, the call
out.print(f)
is equivalent to
out.write(String.valueOf(f).getBytes());
The
println
method appends a line separator after writing its argument
to the streama simple
println
with no parameters ends the current
line. The line separator string is defined by the system property
line.separator
and is not necessarily a single newline character (
\n
).
Each of the
Print
streams acts as a
Filter
stream, so you can filter data
on its way downstream.
The
PrintStream
class acts on byte streams while the
PrintWriter
class
acts on character streams. Because printing is clearly character-related
output, the
PrintWriter
class is the class you should use. However, for
historical reasons
System.out
and
System.err
are
PrintStream
s that use the
default character set encodingthese are the only
PrintStream
objects you
should use. We describe only the
PrintWriter
class, though
PrintStream
provides essentially the same interface.
PrintWriter
has eight constructors.
public
PrintWriter(Writer out, boolean autoflush)