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


public class PrintStream

, Closeable

A 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 via the checkError method.
Optionally, a PrintStream can be created so as to flush
automatically; this means that the flush method is
automatically invoked after a byte array is written, one of the
println methods is invoked, or a newline character or byte
('\n') is written.
All characters printed by a PrintStream are converted into
bytes using the platform's default character encoding. The class should be used in situations that require writing
characters rather than bytes.
PrintWriter

| Field Summary |
|---|
Fields inherited from class java.io.FilterOutputStream ![]() |
|---|
out |
| Constructor Summary | |
|---|---|
PrintStream
Creates a new print stream, without automatic line flushing, with the specified file. |
|
PrintStream
Creates a new print stream, without automatic line flushing, with the specified file and charset. |
|
PrintStream
Create a new print stream. |
|
PrintStream
Create a new print stream. |
|
PrintStream
Create a new print stream. |
|
PrintStream
Creates a new print stream, without automatic line flushing, with the specified file name. |
|
PrintStream
Creates a new print stream, without automatic line flushing, with the specified file name and charset. |
|
| Method Summary | |
|---|---|
PrintStream |
append
Appends the specified character to this output stream. |
PrintStream |
append
Appends the specified character sequence to this output stream. |
PrintStream |
append
Appends a subsequence of the specified character sequence to this output stream. |
boolean |
checkError
Flush the stream and check its error state. |
void |
close
Close the stream. |
void |
flush
Flush the stream. |
PrintStream |
format
Writes a formatted string to this output stream using the specified format string and arguments. |
PrintStream |
format
Writes a formatted string to this output stream 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. |
PrintStream |
printf
A convenience method to write a formatted string to this output stream using the specified format string and arguments. |
PrintStream |
printf
A convenience method to write a formatted string to this output stream using the specified format string and arguments. |
void |
println
Terminate the current line by writing the line separator string. |
void |
println
Print a boolean 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 and then terminate the line. |
void |
println
Print a float and then terminate the line. |
void |
println
Print an integer and then terminate the line. |
void |
println
Print a long 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
Set the error state of the stream to true. |
void |
write
Write len bytes from the specified byte array starting at
offset off to this stream. |
void |
write
Write the specified byte to this stream. |
Methods inherited from class java.io.FilterOutputStream ![]() |
|---|
write |
Methods inherited from class java.lang.Object ![]() |
|---|
clone |
| Constructor Detail |
|---|

public PrintStream(OutputStream![]()
![]()
out)
out - The output stream to which values and objects will be
printedPrintWriter.PrintWriter(java.io.OutputStream)


public PrintStream(OutputStream![]()
![]()
out, boolean autoFlush)
out - The output stream to which values and objects will be
printedautoFlush - A boolean; if true, the output buffer will be flushed
whenever a byte array is written, one of the
println methods is invoked, or a newline
character or byte ('\n') is writtenPrintWriter.PrintWriter(java.io.OutputStream, boolean)


public PrintStream(OutputStream![]()
![]()
out, boolean autoFlush, String
![]()
![]()
encoding) throws UnsupportedEncodingException
![]()
![]()
out - The output stream to which values and objects will be
printedautoFlush - A boolean; if true, the output buffer will be flushed
whenever a byte array is written, one of the
println methods is invoked, or a newline
character or byte ('\n') is writtenencoding - The name of a supported
character encoding
UnsupportedEncodingException

- If the named encoding is not supported

public PrintStream(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 print
stream. 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(fileName)
denies write
access to the file

public PrintStream(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 print
stream. 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(fileName)
denies write
access to the file
UnsupportedEncodingException

- If the named charset is not supported

public PrintStream(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 print stream. 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 PrintStream(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 print stream. 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 presentand 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 FilterOutputStream

OutputStream.flush()


public void close()
close

in interface Closeable

close

in class FilterOutputStream

OutputStream.close()


public boolean checkError()
true when the underlying output stream throws an
IOException other than InterruptedIOException,
and when the setError method is invoked. If an operation
on the underlying output stream throws an
InterruptedIOException, then the PrintStream
converts the exception back into an interrupt by doing:
Thread.currentThread().interrupt();
or the equivalent.
IOException other than
InterruptedIOException, or the
setError method has been invoked

protected void setError()
true.

public void write(int b)
flush method will be
invoked.
Note that the byte is written as given; to write a character that
will be translated according to the platform's default character
encoding, use the print(char) or println(char)
methods.
write

in class FilterOutputStream

b - The byte to be writtenprint(char)
,
println(char)
