|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.io.Writer
![]()
![]()
![]()
java.io.PrintWriter
, Flushable
, Appendable

public class PrintWriter

Print formatted representations of objects to a text-output stream. This
class implements all of the 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()
.
| Field Summary | |
|---|---|
protected Writer |
out
The underlying character-output stream of this PrintWriter. |
Fields inherited from class java.io.Writer ![]() |
|---|
lock |
| Constructor Summary | |
|---|---|
PrintWriter
Creates a new PrintWriter, without automatic line flushing, with the specified file. |
|
PrintWriter
Creates a new PrintWriter, without automatic line flushing, with the specified file and charset. |
|
PrintWriter
Create a new PrintWriter, without automatic line flushing, from an existing OutputStream. |
|
PrintWriter
Create a new PrintWriter from an existing OutputStream. |
|
PrintWriter
Creates a new PrintWriter, without automatic line flushing, with the specified file name. |
|
PrintWriter
Creates a new PrintWriter, without automatic line flushing, with the specified file name and charset. |
|
PrintWriter
Create a new PrintWriter, without automatic line flushing. |
|
PrintWriter
Create a new PrintWriter. |
|
| Method Summary | |
|---|---|
PrintWriter |
append
Appends the specified character to this writer. |
PrintWriter |
append
Appends the specified character sequence to this writer. |
PrintWriter |
append
Appends a subsequence of the specified character sequence to this writer. |
boolean |
checkError
Flush the stream if it's not closed and check its error state. |
void |
close
Close the stream. |
void |
flush
Flush the stream. |
PrintWriter |
format
Writes a formatted string to this writer using the specified format string and arguments. |
PrintWriter |
format
Writes a formatted string to this writer using the specified format string and arguments. |
void |
print
Print a boolean value. |
void |
print
Print a character. |
void |
print
Print an array of characters. |
void |
print
Print a double-precision floating-point number. |
void |
print
Print a floating-point number. |
void |
print
Print an integer. |
void |
print
Print a long integer. |
void |
print
Print an object. |
void |
print
Print a string. |
PrintWriter |
printf
A convenience method to write a formatted string to this writer using the specified format string and arguments. |
PrintWriter |
printf
A convenience method to write a formatted string to this writer using the specified format string and arguments. |
void |
println
Terminate the current line by writing the line separator string. |
void |
println
Print a boolean value and then terminate the line. |
void |
println
Print a character and then terminate the line. |
void |
println
Print an array of characters and then terminate the line. |
void |
println
Print a double-precision floating-point number and then terminate the line. |
void |
println
Print a floating-point number and then terminate the line. |
void |
println
Print an integer and then terminate the line. |
void |
println
Print a long integer and then terminate the line. |
void |
println
Print an Object and then terminate the line. |
void |
println
Print a String and then terminate the line. |
protected void |
setError
Indicate that an error has occurred. |
void |
write
Write an array of characters. |
void |
write
Write A Portion of an array of characters. |
void |
write
Write a single character. |
void |
write
Write a string. |
void |
write
Write a portion of a string. |
Methods inherited from class java.lang.Object ![]() |
|---|
clone |
| Field Detail |
|---|

protected Writer![]()
![]()
out
PrintWriter.
| Constructor Detail |
|---|

public PrintWriter(Writer![]()
![]()
out)
out - A character-output stream

public PrintWriter(Writer![]()
![]()
out, boolean autoFlush)
out - A character-output streamautoFlush - A boolean; if true, the println,
printf, or format methods will
flush the output buffer

public PrintWriter(OutputStream![]()
![]()
out)
out - An output streamOutputStreamWriter.OutputStreamWriter(java.io.OutputStream)


public PrintWriter(OutputStream![]()
![]()
out, boolean autoFlush)
out - An output streamautoFlush - A boolean; if true, the println,
printf, or format methods will
flush the output bufferOutputStreamWriter.OutputStreamWriter(java.io.OutputStream)


public PrintWriter(String![]()
![]()
fileName) throws FileNotFoundException
![]()
![]()
OutputStreamWriter
,
which will encode characters using the default charset
for this
instance of the Java virtual machine.
fileName - 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.
FileNotFoundException

- If the given string does not denote an existing, writable
regular file and a new regular file of that name cannot be
created, or if some other error occurs while opening or
creating the file
SecurityException

- If a security manager is present and checkWrite(fileName)
denies write
access to the file

public PrintWriter(String![]()
![]()
fileName, String
![]()
![]()
csn) throws FileNotFoundException
![]()
![]()
, UnsupportedEncodingException
![]()
![]()
OutputStreamWriter
, which will encode characters using the provided
charset.
fileName - 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.csn - The name of a supported charset
FileNotFoundException

- If the given string does not denote an existing, writable
regular file and a new regular file of that name cannot be
created, or if some other error occurs while opening or
creating the file
SecurityException

- If a security manager is present and checkWrite(fileName)
denies write
access to the file
UnsupportedEncodingException

- If the named charset is not supported

public PrintWriter(File![]()
![]()
file) throws FileNotFoundException
![]()
![]()
OutputStreamWriter
,
which will encode characters using the default charset
for this
instance of the Java virtual machine.
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.
FileNotFoundException

- If the given file object does not denote an existing, writable
regular file and a new regular file of that name cannot be
created, or if some other error occurs while opening or
creating the file
SecurityException

- If a security manager is present and checkWrite(file.getPath())
denies write access to the file

public PrintWriter(File![]()
![]()
file, String
![]()
![]()
csn) throws FileNotFoundException
![]()
![]()
, UnsupportedEncodingException
![]()
![]()
OutputStreamWriter
, which will encode characters using the provided
charset.
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.csn - The name of a supported charset
FileNotFoundException

- If the given file object does not denote an existing, writable
regular file and a new regular file of that name cannot be
created, or if some other error occurs while opening or
creating the file
SecurityException

- If a security manager is present and checkWrite(file.getPath())
denies write access to the file
UnsupportedEncodingException

- If the named charset is not supported| Method Detail |
|---|

public void flush()
flush

in interface Flushable

flush

in class Writer

checkError()


public void close()
close

in interface Closeable

close

in class Writer

checkError()


public boolean checkError()

protected void setError()

public void write(int c)
write

in class Writer

c - int specifying a character to be written.