java.lang.Object | |||
↳ | java.io.OutputStream | ||
↳ | java.io.FilterOutputStream | ||
↳ | java.io.PrintStream |
Wraps an existing OutputStream
and provides convenience methods for
writing common data types in a human readable format. This is not to be
confused with DataOutputStream which is used for encoding common data types
so that they can be read back in. No IOException
is thrown by this
class. Instead, callers should use checkError()
to see if a problem
has occurred in this stream.
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.io.FilterOutputStream
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
PrintStream with out as its target
stream. | |||||||||||
Constructs a new
PrintStream with out as its target
stream. | |||||||||||
Constructs a new
PrintStream with out as its target
stream and using the character encoding enc while writing. | |||||||||||
Constructs a new
PrintStream with file as its target. | |||||||||||
Constructs a new
PrintStream with file as its target. | |||||||||||
Constructs a new
PrintStream with the file identified by
fileName as its target. | |||||||||||
Constructs a new
PrintStream with the file identified by
fileName as its target. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Appends the char
c . | |||||||||||
Appends a subsequence of CharSequence
charSequence , or "null" . | |||||||||||
Appends the CharSequence
charSequence , or "null" . | |||||||||||
Flushes this stream and returns the value of the error flag.
| |||||||||||
Closes this print stream.
| |||||||||||
Ensures that all pending data is sent out to the target stream.
| |||||||||||
Writes a string formatted by an intermediate
Formatter to this
stream using the specified locale, format string and arguments. | |||||||||||
Formats
args according to the format string format , and writes the result
to this stream. | |||||||||||
Prints the string representation of the float
f . | |||||||||||
Prints the string representation of the double
d . | |||||||||||
Prints a string to the target stream.
| |||||||||||
Prints the string representation of the Object
o , or "null" . | |||||||||||
Prints the string representation of the char
c . | |||||||||||
Prints the string representation of the character array
chars . | |||||||||||
Prints the string representation of the long
l . | |||||||||||
Prints the string representation of the int
i . | |||||||||||
Prints the string representation of the boolean
b . | |||||||||||
Prints a formatted string.
| |||||||||||
Prints a formatted string.
| |||||||||||
Prints a newline.
| |||||||||||
Prints the string representation of the float
f followed by a newline. | |||||||||||
Prints the string representation of the int
i followed by a newline. | |||||||||||
Prints the string representation of the long
l followed by a newline. | |||||||||||
Prints the string representation of the Object
o , or "null" ,
followed by a newline. | |||||||||||
Prints the string representation of the character array
chars followed by a newline. | |||||||||||
Prints a string followed by a newline.
| |||||||||||
Prints the string representation of the char
c followed by a newline. | |||||||||||
Prints the string representation of the double
d followed by a newline. | |||||||||||
Prints the string representation of the boolean
b followed by a newline. | |||||||||||
Writes one byte to the target stream.
| |||||||||||
Writes
count bytes from buffer starting at offset
to the target stream. |
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Sets the error state of the stream to false.
| |||||||||||
Sets the error flag of this print stream to true.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.io.FilterOutputStream
| |||||||||||
From class
java.io.OutputStream
| |||||||||||
From class
java.lang.Object
| |||||||||||
From interface
java.io.Closeable
| |||||||||||
From interface
java.io.Flushable
| |||||||||||
From interface
java.lang.Appendable
|
Constructs a new PrintStream
with out
as its target
stream. By default, the new print stream does not automatically flush its
contents to the target stream when a newline is encountered.
out | the target output stream. |
---|
NullPointerException | if out is null .
|
---|
Constructs a new PrintStream
with out
as its target
stream. The parameter autoFlush
determines if the print stream
automatically flushes its contents to the target stream when a newline is
encountered.
out | the target output stream. |
---|---|
autoFlush | indicates whether to flush contents upon encountering a newline sequence. |
NullPointerException | if out is null .
|
---|
Constructs a new PrintStream
with out
as its target
stream and using the character encoding enc
while writing. The
parameter autoFlush
determines if the print stream automatically
flushes its contents to the target stream when a newline is encountered.
out | the target output stream. |
---|---|
autoFlush | indicates whether or not to flush contents upon encountering a newline sequence. |
enc | the non-null string describing the desired character encoding. |
NullPointerException | if out or enc are null . |
---|---|
UnsupportedEncodingException | if the encoding specified by enc is not supported.
|
Constructs a new PrintStream
with file
as its target. The
VM's default character set is used for character encoding.
file | the target file. If the file already exists, its contents are removed, otherwise a new file is created. |
---|
FileNotFoundException | if an error occurs while opening or creating the target file. |
---|
Constructs a new PrintStream
with file
as its target. The
character set named csn
is used for character encoding.
file | the target file. If the file already exists, its contents are removed, otherwise a new file is created. |
---|---|
csn | the name of the character set used for character encoding. |
FileNotFoundException | if an error occurs while opening or creating the target file. |
---|---|
NullPointerException | if csn is null . |
UnsupportedEncodingException | if the encoding specified by csn is not supported.
|
Constructs a new PrintStream
with the file identified by
fileName
as its target. The VM's default character
set is used for character encoding.
fileName | the target file's name. If the file already exists, its contents are removed, otherwise a new file is created. |
---|
FileNotFoundException | if an error occurs while opening or creating the target file. |
---|
Constructs a new PrintStream
with the file identified by
fileName
as its target. The character set named csn
is
used for character encoding.
fileName | the target file's name. If the file already exists, its contents are removed, otherwise a new file is created. |
---|---|
csn | the name of the character set used for character encoding. |
FileNotFoundException | if an error occurs while opening or creating the target file. |
---|---|
NullPointerException | if csn is null . |
UnsupportedEncodingException | if the encoding specified by csn is not supported.
|
Appends the char c
.
c | the character to append. |
---|
Appends a subsequence of CharSequence charSequence
, or "null"
.
charSequence | the character sequence appended to the target stream. |
---|---|
start | the index of the first char in the character sequence appended to the target stream. |
end | the index of the character following the last character of the subsequence appended to the target stream. |
IndexOutOfBoundsException | if start > end , start < 0 , end < 0 or
either start or end are greater or equal than
the length of charSequence .
|
---|
Appends the CharSequence charSequence
, or "null"
.
charSequence | the character sequence to append. |
---|
Flushes this stream and returns the value of the error flag.
true
if either an IOException
has been thrown
previously or if setError()
has been called;
false
otherwise.Closes this print stream. Flushes this stream and then closes the target
stream. If an I/O error occurs, this stream's error state is set to
true
.
Ensures that all pending data is sent out to the target stream. It also
flushes the target stream. If an I/O error occurs, this stream's error
state is set to true
.
Writes a string formatted by an intermediate Formatter
to this
stream using the specified locale, format string and arguments.
l | the locale used in the method. No localization will be applied
if l is null . |
---|---|
format | the format string (see format(String, Object...) ) |
args | the list of arguments passed to the formatter. If there are
more arguments than required by format ,
additional arguments are ignored. |
IllegalFormatException | if the format string is illegal or incompatible with the arguments, if there are not enough arguments or if any other error regarding the format string or arguments is detected. |
---|---|
NullPointerException | if format == null
|
Formats args
according to the format string format
, and writes the result
to this stream. This method uses the user's default locale.
See "Be wary of the default locale".
format | the format string (see format(String, Object...) ) |
---|---|
args | the list of arguments passed to the formatter. If there are
more arguments than required by format ,
additional arguments are ignored. |
IllegalFormatException | if the format string is illegal or incompatible with the arguments, if there are not enough arguments or if any other error regarding the format string or arguments is detected. |
---|---|
NullPointerException | if format == null
|
Prints a string to the target stream. The string is converted to an array
of bytes using the encoding chosen during the construction of this
stream. The bytes are then written to the target stream with
write(int)
.
If an I/O error occurs, this stream's error state is set to true
.
str | the string to print to the target stream. |
---|
Prints the string representation of the Object o
, or "null"
.
Prints the string representation of the character array chars
.
Prints a formatted string. The behavior of this method is the same as
this stream's #format(Locale, String, Object...)
method.
l | the locale used in the method. No localization will be applied
if l is null . |
---|---|
format | the format string (see format(String, Object...) ) |
args | the list of arguments passed to the formatter. If there are
more arguments than required by format ,
additional arguments are ignored. |
IllegalFormatException | if the format string is illegal or incompatible with the arguments, if there are not enough arguments or if any other error regarding the format string or arguments is detected. |
---|---|
NullPointerException | if format == null .
|
Prints a formatted string. The behavior of this method is the same as
this stream's #format(String, Object...)
method.
The Locale
used is the user's default locale.
See "Be wary of the default locale".
format | the format string (see format(String, Object...) ) |
---|---|
args | the list of arguments passed to the formatter. If there are
more arguments than required by format ,
additional arguments are ignored. |
IllegalFormatException | if the format string is illegal or incompatible with the arguments, if there are not enough arguments or if any other error regarding the format string or arguments is detected. |
---|---|
NullPointerException | if format == null
|
Prints the string representation of the float f
followed by a newline.
Prints the string representation of the int i
followed by a newline.
Prints the string representation of the long l
followed by a newline.
Prints the string representation of the Object o
, or "null"
,
followed by a newline.
Prints the string representation of the character array chars
followed by a newline.
Prints a string followed by a newline. The string is converted to an array of bytes using
the encoding chosen during the construction of this stream. The bytes are
then written to the target stream with write(int)
.
If an I/O error occurs, this stream's error state is set to true
.
str | the string to print to the target stream. |
---|
Prints the string representation of the char c
followed by a newline.
Prints the string representation of the double d
followed by a newline.
Prints the string representation of the boolean b
followed by a newline.
Writes one byte to the target stream. Only the least significant byte of
the integer oneByte
is written. This stream is flushed if
oneByte
is equal to the character '\n'
and this stream is
set to autoFlush.
This stream's error flag is set to true
if it is closed or an I/O
error occurs.
oneByte | the byte to be written |
---|
Writes count
bytes from buffer
starting at offset
to the target stream. If autoFlush is set, this stream gets flushed after
writing the buffer.
This stream's error flag is set to true
if this stream is closed
or an I/O error occurs.
buffer | the buffer to be written. |
---|---|
offset | the index of the first byte in buffer to write. |
length | the number of bytes in buffer to write. |
IndexOutOfBoundsException | if offset < 0 or count < 0 , or if offset + count is bigger than the length of buffer . |
---|