java.io.PrintStream
PrintStream
adds functionality to another output stream-namely, the ability
to print representations of various data values conveniently. Two other features are
provided as well. Unlike other output streams, a PrintStream
never throws an
IOException
; instead, exceptional situations merely set an internal flag that can
be tested by the checkError
method. Optionally, a PrintStream
can be created
so as to "autoflush"; this means that after an array of bytes is written, or after a
single byte equal to '\n'
is written, the flush
method is automatically invoked.
public classPrintStream
extends FilterOutputStream { publicPrintStream
(OutputStream out); publicPrintStream
(OutputStream out, boolean autoflush); public voidwrite
(int b); public voidwrite
(byte[] b, int off, int len) throws NullPointerException, IndexOutOfBoundsException; public voidflush
(); public voidclose
(); public booleancheckError
(); public voidprintln
(); public voidprintln
(Object obj); public voidprintln
(String s); public voidprintln
(char[] s) throws NullPointerException; public voidprintln
(boolean b); public voidprintln
(char c); public voidprintln
(int i); public voidprintln
(long l); public voidprintln
(float f); public voidprintln
(double d); }
22.22.1 public
PrintStream
(OutputStream out)
This constructor initializes a newly created PrintStream
by saving its argument,
the output stream out
, for later use. This stream will not autoflush.
22.22.2 public
PrintStream
(OutputStream out, boolean autoflush)
This constructor initializes a newly created PrintStream
by saving its argument,
the output stream out
, for later use. This stream will autoflush if and only if
autoflush
is true
.
22.22.3 public void
write
(int b)
See the general contract of the write
method of OutputStream
(§22.15.1).
Overrides the write
method of FilterOutputStream
(§22.19.3).
22.22.4 public void
write
(byte[] b, int off, int len)
throws NullPointerException, IndexOutOfBoundsException
See the general contract of the write
method of OutputStream
(§22.15.3).
Overrides the write
method of FilterOutputStream
(§22.19.5).
22.22.5 public void
flush
()
See the general contract of the flush
method of OutputStream
(§22.15.4).
Overrides the flush
method of FilterOutputStream
(§22.19.6).
22.22.6 public void
close
()
See the general contract of the close
method of OutputStream
(§22.15.5).
Overrides the close
method of FilterOutputStream
(§22.19.7).
22.22.7 public boolean
checkError
()
The result is true
if and only if this output stream has ever encountered any kind
of trouble-that is, if any operation on the contained output stream has ever
resulted in an IOException
other than an InterruptedIOException
. If an
operation on the contained output stream throws an InterruptedIOException
,
then the PrintStream
class converts the exception back to an interrupt by doing:
Thread.currentThread().interrupt();or the equivalent.
22.22.8 public void
print
(Object obj)
The low-order bytes of the characters in the String
that would be produced by
String.valueOf(obj)
(§20.12.38) are written, in order, to the contained output
stream in exactly the manner of the write
method (§22.22.3).
22.22.9 public void
print
(String s)
The low-order bytes of the characters in the string s
are written, in order, to the
contained output stream in exactly the manner of the write
method (§22.22.3).
If s
is null
, then the low-order bytes of the four characters n
, u
, l
, l
are written to
the contained output stream.
22.22.10 public void
print
(char[] s) throws NullPointerException
The low-order bytes of the characters in the character array s
are written, in order,
to the contained output stream in exactly the manner of the write
method
(§22.22.3).
If s
is null
, a NullPointerException
is thrown.
22.22.11 public void
print
(boolean b)
The low-order bytes of the characters in the String
that would be produced by
String.valueOf(b)
(§20.12.41) as a string are written, in order, to the contained
output stream in exactly the manner of the write
method (§22.22.3).
22.22.12 public void
print
(char c)
The low-order byte of the character c
is written to the contained output stream in
exactly the manner of the write
method (§22.22.3).
22.22.13 public void
print
(int i)
The low-order bytes of the characters in the String
that would be produced by
String.valueOf(i)
(§20.12.43) as a string are written, in order, to the contained
output stream in exactly the manner of the write
method (§22.22.3).
22.22.14 public void
print
(long l)
The low-order bytes of the characters in the String
that would be produced by
String.valueOf(l)
(§20.12.44) as a string are written, in order, to the contained
output stream in exactly the manner of the write
method (§22.22.3).
22.22.15 public void
print
(float f)
The low-order bytes of the characters in the String
that would be produced by
String.valueOf(f)
(§20.12.45) as a string are written, in order, to the contained
output stream in exactly the manner of the write
method (§22.22.3).
22.22.16 public void
print
(double d)
The low-order bytes of the characters in the String
that would be produced by
String.valueOf(d)
(§20.12.46) as a string are written, in order, to the contained
output stream in exactly the manner of the write
method (§22.22.3).
22.22.17 public void
println
()
The low-order byte of the newline character '\n'
is written to the contained output
stream in exactly the manner of the write
method (§22.22.3).
22.22.18 public void
println
(Object obj)
This is exactly the same as print(obj)
(§22.22.8) followed by writing the low-
order byte of the newline character '\n'
to the contained output stream.
22.22.19 public void
println
(String s)
This is exactly the same as print(s)
(§22.22.9) followed by writing the low-
order byte of the newline character '\n'
to the contained output stream.
22.22.20 public void
println
(char[] s) throws NullPointerException
This is exactly the same as print(s)
(§22.22.10) followed by writing the low-
order byte of the newline character '\n'
to the contained output stream.
If s
is null
, a NullPointerException
is thrown.
22.22.21 public void
println
(boolean b)
This is exactly the same as print(b)
(§22.22.11) followed by writing the low-
order byte of the newline character '\n'
to the contained output stream.
22.22.22 public void
println
(char c)
This is exactly the same as print(c)
(§22.22.12) followed by writing the low-
order byte of the newline character '\n'
to the contained output stream.
22.22.23 public void
println
(int i)
This is exactly the same as print(i)
(§22.22.13) followed by writing the low-
order byte of the newline character '\n'
to the contained output stream.
22.22.24 public void
println
(long l)
This is exactly the same as print(l)
(§22.22.14) followed by writing the low-
order byte of the newline character '\n'
to the contained output stream.
22.22.25 public void
println
(float f)
This is exactly the same as print(f)
(§22.22.15) followed by writing the low-
order byte of the newline character '\n'
to the contained output stream.
22.22.26 public void
println
(double d)
This is exactly the same as print(d)
(§22.22.16) followed by writing the low-
order byte of the newline character '\n'
to the contained output stream.
Contents | Prev | Next | Index
Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)
Copyright © 1996 Sun Microsystems, Inc.
All rights reserved
Please send any comments or corrections to doug.kramer@sun.com