print
methods found in PrintStream
. It does not contain methods for writing raw bytes, for which
a program should use unencoded byte streams.
Unlike the PrintStream
class, if automatic flushing is enabled
it will be done only when one of the println
, printf
, or
format
methods is invoked, rather than whenever a newline character
happens to be output. These methods use the platform's own notion of line
separator rather than the newline character.
Methods in this class never throw I/O exceptions, although some of its
constructors may. The client may inquire as to whether any errors have
occurred by invoking checkError()
.
This class always replaces malformed and unmappable character sequences with the charset's default replacement string. The java.nio.charset.CharsetEncoder class should be used when more control over the encoding process is required.
Modifier and Type | Field and Description |
---|---|
private final boolean | |
private Formatter | |
protected Writer | out
The underlying character-output stream of this
|
private PrintStream | |
private boolean |
Access | Constructor and Description |
---|---|
public | PrintWriter(Writer
A character-output stream out)Creates a new PrintWriter, without automatic line flushing. |
public | PrintWriter(Writer
A character-output stream out, boolean A boolean; if true, the autoFlush)println ,
printf , or format methods will
flush the output bufferCreates a new PrintWriter. |
public | PrintWriter(OutputStream
An output stream out)Creates a new PrintWriter, without automatic line flushing, from an existing OutputStream. |
public | PrintWriter(OutputStream
An output stream out, boolean A boolean; if true, the autoFlush)println ,
printf , or format methods will
flush the output bufferCreates a new PrintWriter from an existing OutputStream. |
public | PrintWriter(OutputStream
An output stream out, boolean A boolean; if true, the autoFlush, Charset println ,
printf , or format methods will
flush the output bufferA charset charset)Creates a new PrintWriter from an existing OutputStream. |
public | PrintWriter(String
The name of the file to use as the destination of this writer.
If the file exists then it will be truncated to zero size;
otherwise, a new file will be created. The output will be
written to the file and is buffered. fileName)Creates a new PrintWriter, without automatic line flushing, with the specified file name. |
pack-priv | |
private | |
public | PrintWriter(String
The name of the file to use as the destination of this writer.
If the file exists then it will be truncated to zero size;
otherwise, a new file will be created. The output will be
written to the file and is buffered. fileName, String The name of a supported charset csn)Creates a new PrintWriter, without automatic line flushing, with the specified file name and charset. |
public | PrintWriter(String
The name of the file to use as the destination of this writer.
If the file exists then it will be truncated to zero size;
otherwise, a new file will be created. The output will be
written to the file and is buffered. fileName, Charset A charset charset)Creates a new PrintWriter, without automatic line flushing, with the specified file name and charset. |
public | PrintWriter(File
The file to use as the destination of this writer. If the file
exists then it will be truncated to zero size; otherwise, a new
file will be created. The output will be written to the file
and is buffered. file)Creates a new PrintWriter, without automatic line flushing, with the specified file. |
public | PrintWriter(File
The file to use as the destination of this writer. If the file
exists then it will be truncated to zero size; otherwise, a new
file will be created. The output will be written to the file
and is buffered. file, String The name of a supported charset csn)Creates a new PrintWriter, without automatic line flushing, with the specified file and charset. |
public | PrintWriter(File
The file to use as the destination of this writer. If the file
exists then it will be truncated to zero size; otherwise, a new
file will be created. The output will be written to the file
and is buffered. file, Charset A charset charset)Creates a new PrintWriter, without automatic line flushing, with the specified file and charset. |
Modifier and Type | Method and Description |
---|---|
public PrintWriter | Returns: This writerThe character sequence to append. If csq)csq is
null , then the four characters "null" are
appended to this writer.Overrides java. Implements java. Appends the specified character sequence to this writer. |
public PrintWriter | Returns: This writerThe character sequence from which a subsequence will be
appended. If csq, int csq is null , then characters
will be appended as if csq contained the four
characters "null" .The index of the first character in the subsequence start, int The index of the character following the last character in the
subsequence end)Overrides java. Implements java. Appends a subsequence of the specified character sequence to this writer. |
public PrintWriter | Returns: This writerThe 16-bit character to append c)Overrides java. Implements java. Appends the specified character to this writer. |
public boolean | Returns: true if and only if this stream has encountered an
IOException , or the setError method has been
invokedFlushes the stream if it's not closed and checks its error state. |
protected void | |
public void | close()
Implements abstract java. Implements java. Closes the stream and releases any system resources associated with it. |
private void | |
public void | flush()
Implements abstract java. Implements java. Flushes the stream. |
public PrintWriter | Returns: This writerA format string as described in Format string syntax. format, Object... Arguments referenced by the format specifiers in the format
string. If there are more arguments than format specifiers, the
extra arguments are ignored. The number of arguments is
variable and may be zero. The maximum number of arguments is
limited by the maximum dimension of a Java array as defined by
The Java Virtual Machine Specification.
The behaviour on a
args)null argument depends on the conversion.Writes a formatted string to this writer using the specified format string and arguments. |
public PrintWriter | Returns: This writerA format string as described in Format string syntax. format, Object... Arguments referenced by the format specifiers in the format
string. If there are more arguments than format specifiers, the
extra arguments are ignored. The number of arguments is
variable and may be zero. The maximum number of arguments is
limited by the maximum dimension of a Java array as defined by
The Java Virtual Machine Specification.
The behaviour on a
args)null argument depends on the conversion.Writes a formatted string to this writer using the specified format string and arguments. |
private void | |
public void | |
public void | |
public void | |
public void | |
public void | |
public void | |
public void | |
public void | |
public void | |
public PrintWriter | Returns: This writerA format string as described in Format string syntax. format, Object... Arguments referenced by the format specifiers in the format
string. If there are more arguments than format specifiers, the
extra arguments are ignored. The number of arguments is
variable and may be zero. The maximum number of arguments is
limited by the maximum dimension of a Java array as defined by
The Java Virtual Machine Specification.
The behaviour on a
args)null argument depends on the conversion.A convenience method to write a formatted string to this writer using the specified format string and arguments. |
public PrintWriter | Returns: This writerA format string as described in Format string syntax. format, Object... Arguments referenced by the format specifiers in the format
string. If there are more arguments than format specifiers, the
extra arguments are ignored. The number of arguments is
variable and may be zero. The maximum number of arguments is
limited by the maximum dimension of a Java array as defined by
The Java Virtual Machine Specification.
The behaviour on a
args)null argument depends on the conversion.A convenience method to write a formatted string to this writer using the specified format string and arguments. |
public void | |
public void | println(boolean
the x)boolean value to be printedPrints a boolean value and then terminates the line. |
public void | |
public void | |
public void | |
public void | println(float
the x)float value to be printedPrints a floating-point number and then terminates the line. |
public void | println(double
the x)double value to be printedPrints a double-precision floating-point number and then terminates the line. |
public void | println(char[]
the array of x)char values to be printedPrints an array of characters and then terminates the line. |
public void | |
public void | |
protected void | |
private static Charset | |
public void | write(int
int specifying a character to be written. c)Overrides java. Writes a single character. |
public void | write(char[]
Array of characters buf, int Offset from which to start writing characters off, int Number of characters to write len)Implements abstract java. Writes A Portion of an array of characters. |
public void | write(char[]
Array of characters to be written buf)Overrides java. Writes an array of characters. |
public void | write(String
A String s, int Offset from which to start writing characters off, int Number of characters to write len)Overrides java. Writes a portion of a string. |
public void |
autoFlush | back to summary |
---|---|
private final boolean autoFlush |
formatter | back to summary |
---|---|
private Formatter formatter |
out | back to summary |
---|---|
protected Writer out The underlying character-output stream of this
|
psOut | back to summary |
---|---|
private PrintStream psOut |
trouble | back to summary |
---|---|
private boolean trouble |
PrintWriter | back to summary |
---|---|
public PrintWriter(Writer out) Creates a new PrintWriter, without automatic line flushing.
|
PrintWriter | back to summary |
---|---|
public PrintWriter(Writer out, boolean autoFlush) Creates a new PrintWriter.
|
PrintWriter | back to summary |
---|---|
public PrintWriter(OutputStream out) Creates a new PrintWriter, without automatic line flushing, from an
existing OutputStream. This convenience constructor creates the
necessary intermediate OutputStreamWriter, which will convert characters
into bytes using the default charset, or where
|
PrintWriter | back to summary |
---|---|
public PrintWriter(OutputStream out, boolean autoFlush) Creates a new PrintWriter from an existing OutputStream. This
convenience constructor creates the necessary intermediate
OutputStreamWriter, which will convert characters into bytes using
the default charset, or where
|
PrintWriter | back to summary |
---|---|
public PrintWriter(OutputStream out, boolean autoFlush, Charset charset) Creates a new PrintWriter from an existing OutputStream. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will convert characters into bytes using the specified charset.
|
PrintWriter | back to summary |
---|---|
public PrintWriter(String fileName) throws FileNotFoundException Creates a new PrintWriter, without automatic line flushing, with the
specified file name. This convenience constructor creates the necessary
intermediate
|
PrintWriter | back to summary |
---|---|
pack-priv PrintWriter(Writer out, Object lock) |
PrintWriter | back to summary |
---|---|
private PrintWriter(Charset charset, File file) throws FileNotFoundException |
PrintWriter | back to summary |
---|---|
public PrintWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException Creates a new PrintWriter, without automatic line flushing, with the
specified file name and charset. This convenience constructor creates
the necessary intermediate
|
PrintWriter | back to summary |
---|---|
public PrintWriter(String fileName, Charset charset) throws IOException Creates a new PrintWriter, without automatic line flushing, with the
specified file name and charset. This convenience constructor creates
the necessary intermediate
|
PrintWriter | back to summary |
---|---|
public PrintWriter(File file) throws FileNotFoundException Creates a new PrintWriter, without automatic line flushing, with the
specified file. This convenience constructor creates the necessary
intermediate
|
PrintWriter | back to summary |
---|---|
public PrintWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException Creates a new PrintWriter, without automatic line flushing, with the
specified file and charset. This convenience constructor creates the
necessary intermediate
|
PrintWriter | back to summary |
---|---|
public PrintWriter(File file, Charset charset) throws IOException Creates a new PrintWriter, without automatic line flushing, with the
specified file and charset. This convenience constructor creates the
necessary intermediate
|
append | back to summary |
---|---|
public PrintWriter append(CharSequence csq) Overrides java. Implements java. Appends the specified character sequence to this writer. An invocation of this method of the form out.write(csq.toString()) Depending on the specification of
|
append | back to summary |
---|---|
public PrintWriter append(CharSequence csq, int start, int end) Overrides java. Implements java. Appends a subsequence of the specified character sequence to this writer. An invocation of this method of the form
out.write(csq.subSequence(start, end).toString())
|
append | back to summary |
---|---|
public PrintWriter append(char c) Overrides java. Implements java. Appends the specified character to this writer. An invocation of this method of the form out.write(c)
|
checkError | back to summary |
---|---|
public boolean checkError() Flushes the stream if it's not closed and checks its error state.
|
clearError | back to summary |
---|---|
protected void clearError() Clears the error state of this stream. This method will cause subsequent invocations of
|
close | back to summary |
---|---|
public void close() Implements abstract java. Implements java. Closes the stream and releases any system resources associated with it. Closing a previously closed stream has no effect.
|
ensureOpen | back to summary |
---|---|
private void ensureOpen() throws IOException Checks to make sure that the stream has not been closed |
flush | back to summary |
---|---|
public void flush() Implements abstract java. Implements java. Flushes the stream.
|
format | back to summary |
---|---|
public PrintWriter format(String format, Object... args) Writes a formatted string to this writer using the specified format string and arguments. If automatic flushing is enabled, calls to this method will flush the output buffer. The locale always used is the one returned by
|
format | back to summary |
---|---|
public PrintWriter format(Locale l, String format, Object... args) Writes a formatted string to this writer using the specified format string and arguments. If automatic flushing is enabled, calls to this method will flush the output buffer.
|
newLine | back to summary |
---|---|
private void newLine() |
back to summary | |
---|---|
public void print(boolean b) Prints a boolean value. The string produced by
|
back to summary | |
---|---|
public void print(char c) Prints a character. The character is translated into one or more bytes
according to the default charset, and these bytes
are written in exactly the manner of the
|
back to summary | |
---|---|
public void print(int i) Prints an integer. The string produced by
|
back to summary | |
---|---|
public void print(long l) Prints a long integer. The string produced by
|
back to summary | |
---|---|
public void print(float f) Prints a floating-point number. The string produced by
|
back to summary | |
---|---|
public void print(double d) Prints a double-precision floating-point number. The string produced by
|
back to summary | |
---|---|
public void print(char[] s) Prints an array of characters. The characters are converted into bytes
according to the default charset, and these bytes
are written in exactly the manner of the
|
back to summary | |
---|---|
public void print(String s) Prints a string. If the argument is
|
back to summary | |
---|---|
public void print(Object obj) Prints an object. The string produced by the
|
printf | back to summary |
---|---|
public PrintWriter printf(String format, Object... args) A convenience method to write a formatted string to this writer using the specified format string and arguments. If automatic flushing is enabled, calls to this method will flush the output buffer. An invocation of this method of the form
out.format(format, args)
|
printf | back to summary |
---|---|
public PrintWriter printf(Locale l, String format, Object... args) A convenience method to write a formatted string to this writer using the specified format string and arguments. If automatic flushing is enabled, calls to this method will flush the output buffer. An invocation of this method of the form
out.format(l, format, args)
|
println | back to summary |
---|---|
public void println() Terminates the current line by writing the line separator string. The
line separator is |
println | back to summary |
---|---|
public void println(boolean x) Prints a boolean value and then terminates the line. This method behaves
as though it invokes
|
println | back to summary |
---|---|
public void println(char x) Prints a character and then terminates the line. This method behaves as
though it invokes
|
println | back to summary |
---|---|
public void println(int x) Prints an integer and then terminates the line. This method behaves as
though it invokes
|
println | back to summary |
---|---|
public void println(long x) Prints a long integer and then terminates the line. This method behaves
as though it invokes
|
println | back to summary |
---|---|
public void println(float x) Prints a floating-point number and then terminates the line. This method
behaves as though it invokes
|
println | back to summary |
---|---|
public void println(double x) Prints a double-precision floating-point number and then terminates the
line. This method behaves as though it invokes
|
println | back to summary |
---|---|
public void println(char[] x) Prints an array of characters and then terminates the line. This method
behaves as though it invokes
|
println | back to summary |
---|---|
public void println(String x) Prints a String and then terminates the line. This method behaves as
though it invokes
|
println | back to summary |
---|---|
public void println(Object x) Prints an Object and then terminates the line. This method calls
at first String.valueOf(x) to get the printed object's string value,
then behaves as
though it invokes
|
setError | back to summary |
---|---|
protected void setError() Sets the error state of the stream to This method will cause subsequent invocations of |
toCharset | back to summary |
---|---|
private static Charset toCharset(String csn) throws UnsupportedEncodingException Returns a charset object for the given charset name.
|
write | back to summary |
---|---|
public void write(int c) Overrides java. Writes a single character.
|
write | back to summary |
---|---|
public void write(char[] buf, int off, int len) Implements abstract java. Writes A Portion of an array of characters.
|
write | back to summary |
---|---|
public void write(char[] buf) Overrides java. Writes an array of characters. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.
|
write | back to summary |
---|---|
public void write(String s, int off, int len) Overrides java. Writes a portion of a string.
|
write | back to summary |
---|---|
public void write(String s) Overrides java. Writes a string. This method cannot be inherited from the Writer class because it must suppress I/O exceptions.
|