| java.lang.Object | ||
| ↳ | java.io.Writer | |
| ↳ | java.io.PrintWriter | |
PrintWriter is a class which takes either an OutputStream or Writer and provides convenience methods for printing common data types in a human readable format on the stream. No IOExceptions are thrown by this class. Instead, callers should call checkError() to see if a problem has been encountered in this Writer.
| Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| out | The writer to output data to. | ||||||||||
|
[Expand]
Inherited Fields | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.io.Writer
| |||||||||||
| Public Constructors | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new PrintWriter on the OutputStream
out. | |||||||||||
Constructs a new PrintWriter on the OutputStream
out. | |||||||||||
Constructs a new PrintWriter on the Writer
wr. | |||||||||||
Constructs a new PrintWriter on the given writer.
| |||||||||||
Constructs a new PrintWriter on the File
file. | |||||||||||
Constructs a new PrintWriter on the File
file. | |||||||||||
Constructs a new PrintWriter on a file with the given file name
fileName. | |||||||||||
Constructs a new PrintWriter on a file with the given file name
fileName. | |||||||||||
| Public Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Append a char
cto the PrintWriter. | |||||||||||
Append a CharSequence
csq to the PrintWriter. | |||||||||||
Append a subsequence of a CharSequence
csq to the
PrintWriter. | |||||||||||
Returns a boolean indicating whether or not this PrintWriter has
encountered an error.
| |||||||||||
Close this PrintWriter.
| |||||||||||
Flush this PrintWriter to ensure all pending data is sent out to the
target Writer.
| |||||||||||
Writes a string formatted by an intermediate
Formatter to
this writer using the given format string and arguments. | |||||||||||
Writes a string formatted by an intermediate
Formatter to
this writer using the given format string and arguments. | |||||||||||
Prints the String representation of the
float parameter
fnum to the target Writer. | |||||||||||
Prints the String representation of the character parameter
ch to the target Writer. | |||||||||||
Prints the String representation of the Object parameter
obj
to the target Writer. | |||||||||||
Prints the String representation of the
String parameter
str to the target Writer. | |||||||||||
Prints the String representation of the
int parameter
inum to the target Writer. | |||||||||||
Prints the String representation of the
double parameter
dnum to the target Writer. | |||||||||||
Prints the String representation of the
long parameter
lnum to the target Writer. | |||||||||||
Prints the String representation of the character array parameter
charArray to the target Writer. | |||||||||||
Prints the String representation of the
boolean parameter
bool to the target Writer. | |||||||||||
Prints a formatted string.
| |||||||||||
Prints a formatted string.
| |||||||||||
Prints the String representation of the
double parameter
dnum to the target Writer followed by the System property
"line.separator". | |||||||||||
Prints the String representation of the
String parameter
str to the target Writer followed by the System property
"line.separator". | |||||||||||
Prints the String representation of the
boolean parameter
bool to the target Writer followed by the System property
"line.separator". | |||||||||||
Prints the String representation of the
long parameter
lnum to the target Writer followed by the System property
"line.separator". | |||||||||||
Prints the String representation of the character parameter
ch to the target Writer followed by the System property
"line.separator". | |||||||||||
Prints the String representation of the
float parameter
fnum to the target Writer followed by the System property
"line.separator". | |||||||||||
Prints the String representation of the character array parameter
charArray to the target Writer followed by the System
property "line.separator". | |||||||||||
Prints the String representation of the
Object parameter
obj to the target Writer followed by the System property
"line.separator". | |||||||||||
Prints the String representation of the System property
"line.separator" to the target Writer. | |||||||||||
Prints the String representation of the
int parameter
inum to the target Writer followed by the System property
"line.separator". | |||||||||||
Writes the entire character buffer buf to this Writer.
| |||||||||||
Writes the characters from the String
str to this Writer. | |||||||||||
Writes
count characters from the String str
starting at offset to this Writer. | |||||||||||
Writes the specified character to this Writer.
| |||||||||||
Writes
count characters starting at offset
in buf | |||||||||||
| Protected Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
Set the flag indicating that this PrintWriter has encountered an IO
error.
| |||||||||||
|
[Expand]
Inherited Methods | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
From class java.io.Writer
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface java.io.Closeable
| |||||||||||
From interface java.io.Flushable
| |||||||||||
From interface java.lang.Appendable
| |||||||||||
The writer to output data to.
Constructs a new PrintWriter on the OutputStream out. All
writes to the target can now take place through this PrintWriter. By
default, the PrintWriter is set to not autoflush when println() is
called.
| out | the the OutputStream to provide convenience methods on. |
|---|
Constructs a new PrintWriter on the OutputStream out. All
writes to the target can now take place through this PrintWriter. By
default, the PrintWriter is set to not autoflush when println() is
called.
| out | the the OutputStream to provide convenience methods on. |
|---|---|
| autoflush | whether to flush when println() is called. |
Constructs a new PrintWriter on the Writer wr. All writes
to the target can now take place through this PrintWriter. By default,
the PrintWriter is set to not autoflush when println() is called.
| wr | the Writer to provide convenience methods on. |
|---|
Constructs a new PrintWriter on the given writer. All writes to the target can now take place through this PrintWriter. By default, the PrintWriter is set to not autoflush when println() is called.
| wr | the Writer to provide convenience methods on. |
|---|---|
| autoflush | whether to flush when println() is called. |
Constructs a new PrintWriter on the File file. The
automatic flushing is set to false. An intermediate
OutputStreamWriter will use the default for the current
JVM instance charset to encode characters.
| file | This writer's buffered destination. |
|---|
| FileNotFoundException | If there is no such a file or some other error occurs due to the given file opening. |
|---|
Constructs a new PrintWriter on the File file. The
automatic flushing is set to false. An intermediate
OutputStreamWriter will use a charset with the given name
csn to encode characters.
| file | This writer's buffered destination. |
|---|---|
| csn | A charset name. |
| FileNotFoundException | If there is no such a file or some other error occurs due to the given file opening. |
|---|---|
| UnsupportedEncodingException | If a charset with the given name is not supported. |
Constructs a new PrintWriter on a file with the given file name
fileName. The automatic flushing is set to
false. An intermediate OutputStreamWriter
will use the default for the current JVM instance charset to encode
characters.
| fileName | The name of file which is this writer's buffered destination. |
|---|
| FileNotFoundException | If there is no such a file or some other error occurs due to the given file opening. |
|---|
Constructs a new PrintWriter on a file with the given file name
fileName. The automatic flushing is set to
false. An intermediate OutputStreamWriter
will use a charset with the given name csn to encode
characters.
| fileName | The name of file which is this writer's buffered destination. |
|---|---|
| csn | A charset name. |
| FileNotFoundException | If there is no such a file or some other error occurs due to the given file opening. |
|---|---|
| UnsupportedEncodingException | If a charset with the given name is not supported. |
Append a char cto the PrintWriter. The
PrintWriter.append(c) works the same way as
PrintWriter.write(c).
| c | The character appended to the PrintWriter. |
|---|
Append a CharSequence csq to the PrintWriter. The
PrintWriter.append(csq) works the same way as
PrintWriter.write(csq.toString()). If csq
is null, then "null" will be substituted for csq
| csq | The CharSequence appended to the PrintWriter. |
|---|
Append a subsequence of a CharSequence csq to the
PrintWriter. The first char and the last char of the subsequence is
specified by the parameter start and end.
The PrintWriter.append(csq) works the same way as
PrintWriter.write(csq.subSequence(start,end).toString).If
csq is null, then "null" will be substituted for
csq.
| csq | The CharSequence appended to the PrintWriter. |
|---|---|
| start | The index of the first char in the CharSequence appended to the PrintWriter. |
| end | The index of the char after the last one in the CharSequence appended to the PrintWriter. |
| IndexOutOfBoundsException | If start is less than end, end is greater than the length of the CharSequence, or start or end is negative. |
|---|
Returns a boolean indicating whether or not this PrintWriter has encountered an error. If so, the receiver should probably be closed since further writes will not actually take place. A side effect of calling checkError is that the target Writer is flushed.
Close this PrintWriter. This implementation flushes and then closes the
target writer. If an error occurs, set an error in this PrintWriter to
true.
Flush this PrintWriter to ensure all pending data is sent out to the
target Writer. This implementation flushes the target writer. If an error
occurs, set an error in this PrintWriter to true.
Writes a string formatted by an intermediate Formatter to
this writer using the given format string and arguments. A call to this
method flushes the buffered output, if the automatic flushing is enabled.
The method uses the default for the current JVM instance locale, as if it
is specified by the Locale.getDefault() call.
| format | A format string. |
|---|---|
| args | The arguments list. If there are more arguments than those specified by the format string, then the additional arguments are ignored. |
| IllegalFormatException | If the format string is illegal or incompatible with the arguments or the arguments are less than those required by the format string or any other illegal situation. |
|---|---|
| NullPointerException | If the given format is null. |
Writes a string formatted by an intermediate Formatter to
this writer using the given format string and arguments. A call to this
method flushes the buffered output, if the automatic flushing is enabled.
| l | The locale used in the method. If locale is null, then no localization will be applied. |
|---|---|
| format | A format string. |
| args | The arguments list. If there are more arguments than those specified by the format string, then the additional arguments are ignored. |
| IllegalFormatException | If the format string is illegal or incompatible with the arguments or the arguments are less than those required by the format string or any other illegal situation. |
|---|---|
| NullPointerException | If the given format is null. |
Prints the String representation of the float parameter
fnum to the target Writer.
| fnum | the float to print on this Writer.
|
|---|
Prints the String representation of the character parameter
ch to the target Writer.
| ch | the character to print on this Writer. |
|---|
Prints the String representation of the Object parameter obj
to the target Writer.
| obj | the Object to print on this Writer. |
|---|
Prints the String representation of the String parameter
str to the target Writer.
| str | the String to print on this Writer.
|
|---|
Prints the String representation of the int parameter
inum to the target Writer.
| inum | the int to print on this Writer.
|
|---|
Prints the String representation of the double parameter
dnum to the target Writer.
| dnum | the double to print on this Writer.
|
|---|
Prints the String representation of the long parameter
lnum to the target Writer.
| lnum | the long to print on this Writer.
|
|---|
Prints the String representation of the character array parameter
charArray to the target Writer.
| charArray | the character array to print on this Writer. |
|---|
Prints the String representation of the boolean parameter
bool to the target Writer.
| bool | the boolean to print on this Writer.
|
|---|
Prints a formatted string. The behavior of this method is the same as
this writer's
format(Locale l, String format, Object... args) method.
| l | The locale used in the method. If locale is null, then no localization will be applied. |
|---|---|
| format | A format string. |
| args | The arguments list. If there are more arguments than those specified by the format string, then the additional arguments are ignored. |
| IllegalFormatException | If the format string is illegal or incompatible with the arguments or the arguments are less than those required by the format string or any other illegal situation. |
|---|---|
| NullPointerException | If the given format is null. |
Prints a formatted string. The behavior of this method is the same as
this writer's format(String format, Object... args)
method.
The method uses the default for the current JVM instance locale, as if it
is specified by the Locale.getDefault() call.
| format | A format string. |
|---|---|
| args | The arguments list. If there are more arguments than those specified by the format string, then the additional arguments are ignored. |
| IllegalFormatException | If the format string is illegal or incompatible with the arguments or the arguments are less than those required by the format string or any other illegal situation. |
|---|---|
| NullPointerException | If the given format is null. |
Prints the String representation of the double parameter
dnum to the target Writer followed by the System property
"line.separator".
| dnum | the double to print on this Writer. |
|---|
Prints the String representation of the String parameter
str to the target Writer followed by the System property
"line.separator".
| str | the String to print on this Writer.
|
|---|
Prints the String representation of the boolean parameter
bool to the target Writer followed by the System property
"line.separator".
| bool | the boolean to print on this Writer. |
|---|
Prints the String representation of the long parameter
lnum to the target Writer followed by the System property
"line.separator".
| lnum | the long to print on this Writer. |
|---|
Prints the String representation of the character parameter
ch to the target Writer followed by the System property
"line.separator".
| ch | the character to print on this Writer. |
|---|
Prints the String representation of the float parameter
fnum to the target Writer followed by the System property
"line.separator".
| fnum | the float to print on this Writer. |
|---|
Prints the String representation of the character array parameter
charArray to the target Writer followed by the System
property "line.separator".
| charArray | the character array to print on this Writer. |
|---|
Prints the String representation of the Object parameter
obj to the target Writer followed by the System property
"line.separator".
| obj | the Object to print on this Writer.
|
|---|
Prints the String representation of the System property
"line.separator" to the target Writer.
Prints the String representation of the int parameter
inum to the target Writer followed by the System property
"line.separator".
| inum | the int to print on this Writer. |
|---|
Writes the entire character buffer buf to this Writer.
| buf | the non-null array containing characters to write. |
|---|
Writes the characters from the String str to this Writer.
| str | the non-null String containing the characters to write. |
|---|
Writes count characters from the String str
starting at offset to this Writer.
| str | the non-null String containing the characters to write. |
|---|---|
| offset | where in str to get chars from. |
| count | how many characters to write. |
| ArrayIndexOutOfBoundsException | If offset or count are outside of bounds. |
|---|
Writes the specified character to this Writer. This implementation writes the low order two bytes to the target writer.
| oneChar | The character to write |
|---|
Writes count characters starting at offset
in buf
to this Writer.
| buf | the non-null array containing characters to write. |
|---|---|
| offset | offset in buf to retrieve characters |
| count | maximum number of characters to write |
| ArrayIndexOutOfBoundsException | If offset or count are outside of bounds. |
|---|
Set the flag indicating that this PrintWriter has encountered an IO error.