|
|||||||||
| Home >> All >> java >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.io
Class PrintWriter

java.lang.Objectjava.io.Writer
java.io.PrintWriter
- public class PrintWriter
- extends Writer
This class prints Java primitive values and objects to a stream as
text. None of the methods in this class throw an exception. However,
errors can be detected by calling the checkError() method.
Additionally, this stream can be designated as "autoflush" when
created so that any writes are automatically flushed to the underlying
output sink whenever one of the println methods is
called. (Note that this differs from the PrintStream
class which also auto-flushes when it encounters a newline character
in the chars written).
| Field Summary | |
private boolean |
autoflush
true if auto-flush is enabled, false otherwise |
private boolean |
closed
Indicates whether or not the stream has been closed. |
private boolean |
error
This boolean indicates whether or not an error has ever occurred on this stream. |
private static char[] |
line_separator
This is the system dependent line separator |
protected Writer |
out
This is the underlying Writer we are sending output
to |
| Fields inherited from class java.io.Writer |
lock |
| Constructor Summary | |
PrintWriter(File file)
This initializes a new PrintWriter object to write to the specified file. |
|
PrintWriter(File file,
java.lang.String enc)
This initializes a new PrintWriter object to write to the specified file. |
|
PrintWriter(OutputStream out)
This method initializes a new PrintWriter object to write
to the specified OutputStream. |
|
PrintWriter(OutputStream out,
boolean autoflush)
This method initializes a new PrintWriter object to write
to the specified OutputStream. |
|
PrintWriter(java.lang.String file)
This initializes a new PrintWriter object to write to the specified file. |
|
PrintWriter(java.lang.String file,
java.lang.String enc)
This initializes a new PrintWriter object to write to the specified file. |
|
PrintWriter(Writer wr)
This method intializes a new PrintWriter object to write
to the specified output sink. |
|
PrintWriter(Writer wr,
boolean autoflush)
This method intializes a new PrintWriter object to write
to the specified output sink. |
|
| Method Summary | |
boolean |
checkError()
This method checks to see if an error has occurred on this stream. |
void |
close()
This method closes this stream and all underlying streams. |
void |
flush()
This method flushes any buffered chars to the underlying stream and then flushes that stream as well. |
void |
print(boolean bool)
This methods prints a boolean value to the stream. |
void |
print(char ch)
This method prints a char to the stream. |
void |
print(char[] charArray)
This method prints an array of characters to the stream. |
void |
print(double dnum)
This method prints a double to the stream. |
void |
print(float fnum)
This method prints a float to the stream. |
void |
print(int inum)
This method prints an integer to the stream. |
void |
print(long lnum)
This method prints a long to the stream. |
void |
print(java.lang.Object obj)
This method prints an Object to the stream. |
void |
print(java.lang.String str)
This method prints a String to the stream. |
void |
println()
This method prints a line separator sequence to the stream. |
void |
println(boolean bool)
This methods prints a boolean value to the stream. |
void |
println(char ch)
This method prints a char to the stream. |
void |
println(char[] charArray)
This method prints an array of characters to the stream. |
void |
println(double dnum)
This method prints a double to the stream. |
void |
println(float fnum)
This method prints a float to the stream. |
void |
println(int inum)
This method prints an integer to the stream. |
void |
println(long lnum)
This method prints a long to the stream. |
void |
println(java.lang.Object obj)
This method prints an Object to the stream. |
void |
println(java.lang.String str)
This method prints a String to the stream. |
protected void |
setError()
This method can be called by subclasses to indicate that an error has occurred and should be reported by checkError. |
void |
write(char[] charArray)
This method write all the chars in the specified array to the output. |
void |
write(char[] charArray,
int offset,
int count)
This method writes count chars from the specified array
starting at index offset into the array. |
void |
write(int ch)
This method writes a single char to the stream. |
void |
write(java.lang.String str)
This method writes the contents of the specified String
to the underlying stream. |
void |
write(java.lang.String str,
int offset,
int count)
This method writes count chars from the specified
String to the output starting at character position
offset into the String |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
autoflush
private boolean autoflush
trueif auto-flush is enabled,falseotherwise
error
private boolean error
- This boolean indicates whether or not an error has ever occurred
on this stream.
closed
private boolean closed
- Indicates whether or not the stream has been closed.
out
protected Writer out
- This is the underlying
Writerwe are sending output to
line_separator
private static final char[] line_separator
- This is the system dependent line separator
| Constructor Detail |
PrintWriter
public PrintWriter(Writer wr)
- This method intializes a new
PrintWriterobject to write to the specified output sink. The form of the constructor does not enable auto-flush functionality.
PrintWriter
public PrintWriter(Writer wr, boolean autoflush)
- This method intializes a new
PrintWriterobject to write to the specified output sink. This constructor also allows "auto-flush" functionality to be specified where the stream will be flushed after every line is terminated or newline character is written.
PrintWriter
public PrintWriter(OutputStream out)
- This method initializes a new
PrintWriterobject to write to the specifiedOutputStream. Characters will be converted to chars using the system default encoding. Auto-flush functionality will not be enabled.
PrintWriter
public PrintWriter(OutputStream out, boolean autoflush)
- This method initializes a new
PrintWriterobject to write to the specifiedOutputStream. Characters will be converted to chars using the system default encoding. This form of the constructor allows auto-flush functionality to be enabled if desired
PrintWriter
public PrintWriter(java.lang.String file) throws FileNotFoundException
- This initializes a new PrintWriter object to write to the specified
file. It creates a FileOutputStream object and wraps it in an
OutputStreamWriter using the default encoding.
- Since:
- 1.5
PrintWriter
public PrintWriter(java.lang.String file, java.lang.String enc) throws FileNotFoundException, UnsupportedEncodingException
- This initializes a new PrintWriter object to write to the specified
file. It creates a FileOutputStream object and wraps it in an
OutputStreamWriter using the specified encoding.
- Since:
- 1.5
PrintWriter
public PrintWriter(File file) throws FileNotFoundException
- This initializes a new PrintWriter object to write to the specified
file. It creates a FileOutputStream object and wraps it in an
OutputStreamWriter using the default encoding.
- Since:
- 1.5
PrintWriter
public PrintWriter(File file, java.lang.String enc) throws FileNotFoundException, UnsupportedEncodingException
- This initializes a new PrintWriter object to write to the specified
file. It creates a FileOutputStream object and wraps it in an
OutputStreamWriter using the specified encoding.
- Since:
- 1.5
| Method Detail |
setError
protected void setError()
- This method can be called by subclasses to indicate that an error
has occurred and should be reported by
checkError.
checkError
public boolean checkError()
- This method checks to see if an error has occurred on this stream. Note
that once an error has occurred, this method will continue to report
trueforever for this stream. Before checking for an error condition, this method flushes the stream.
flush
public void flush()
- This method flushes any buffered chars to the underlying stream and
then flushes that stream as well.
close
public void close()
public void print(java.lang.String str)
- This method prints a
Stringto the stream. The actual value printed depends on the system default encoding.
public void print(char ch)
- This method prints a char to the stream. The actual value printed is
determined by the character encoding in use.
public void print(char[] charArray)
- This method prints an array of characters to the stream. The actual
value printed depends on the system default encoding.
public void print(boolean bool)
- This methods prints a boolean value to the stream.
truevalues are printed as "true" andfalsevalues are printed as "false".
public void print(int inum)
- This method prints an integer to the stream. The value printed is
determined using the
String.valueOf()method.
public void print(long lnum)
- This method prints a long to the stream. The value printed is
determined using the
String.valueOf()method.
public void print(float fnum)
- This method prints a float to the stream. The value printed is
determined using the
String.valueOf()method.
public void print(double dnum)
- This method prints a double to the stream. The value printed is
determined using the
String.valueOf()method.
public void print(java.lang.Object obj)
- This method prints an
Objectto the stream. The actual value printed is determined by calling theString.valueOf()method.
println
public void println()
- This method prints a line separator sequence to the stream. The value
printed is determined by the system property
line.separator and is not necessarily the Unix '\n' newline character.
println
public void println(boolean bool)
- This methods prints a boolean value to the stream.
truevalues are printed as "true" andfalsevalues are printed as "false". This method prints a line termination sequence after printing the value.
println
public void println(int inum)
- This method prints an integer to the stream. The value printed is
determined using the
String.valueOf()method. This method prints a line termination sequence after printing the value.
println
public void println(long lnum)
- This method prints a long to the stream. The value printed is
determined using the
String.valueOf()method. This method prints a line termination sequence after printing the value.
println
public void println(float fnum)
- This method prints a float to the stream. The value printed is
determined using the
String.valueOf()method. This method prints a line termination sequence after printing the value.
println
public void println(double dnum)
- This method prints a double to the stream. The value printed is
determined using the
String.valueOf()method. This method prints a line termination sequence after printing the value.
println
public void println(java.lang.Object obj)
- This method prints an
Objectto the stream. The actual value printed is determined by calling theString.valueOf()method. This method prints a line termination sequence after printing the value.
println
public void println(java.lang.String str)
- This method prints a
Stringto the stream. The actual value printed depends on the system default encoding. This method prints a line termination sequence after printing the value.
println
public void println(char ch)
- This method prints a char to the stream. The actual value printed is
determined by the character encoding in use.
This method prints a line termination sequence after printing the value.
println
public void println(char[] charArray)
- This method prints an array of characters to the stream. The actual
value printed depends on the system default encoding.
This method prints a line termination sequence after printing the value.
write
public void write(int ch)
write
public void write(char[] charArray,
int offset,
int count)
- This method writes
countchars from the specified array starting at indexoffsetinto the array.
write
public void write(java.lang.String str, int offset, int count)
- This method writes
countchars from the specifiedStringto the output starting at character positionoffsetinto theString
write
public void write(char[] charArray)
- This method write all the chars in the specified array to the output.
write
public void write(java.lang.String str)
- This method writes the contents of the specified
Stringto the underlying stream.
|
|||||||||
| Home >> All >> java >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC