Class java.io.PrintWriter
java.lang.Object
|
+----java.io.Writer
|
+----java.io.PrintWriter
- public class PrintWriter
- extends Writer
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() methods is invoked, rather than
whenever a newline character happens to be output. The println() methods
use the platform's own notion of line separator rather than the newline
character.
Methods in this class never throw I/O exceptions. The client may
inquire as to whether any errors have occurred by invoking checkError().
- Since:
- JDK1.1
Method Summary
|
boolean
|
checkError()
Flush the stream and check its error state.
|
void
|
close()
Close the stream.
|
void
|
flush()
Flush the stream.
|
void
|
print(boolean b)
Print a boolean.
|
void
|
print(char c)
Print a character.
|
void
|
print(int i)
Print an integer.
|
void
|
print(long l)
Print a long.
|
void
|
print(float f)
Print a float.
|
void
|
print(double d)
Print a double.
|
void
|
print(char[] s)
Print an array of chracters.
|
void
|
print(String s)
Print a String.
|
void
|
print(Object obj)
Print an object.
|
void
|
println()
Finish the line.
|
void
|
println(boolean x)
Print a boolean, and then finish the line.
|
void
|
println(char x)
Print a character, and then finish the line.
|
void
|
println(int x)
Print an integer, and then finish the line.
|
void
|
println(long x)
Print a long, and then finish the line.
|
void
|
println(float x)
Print a float, and then finish the line.
|
void
|
println(double x)
Print a double, and then finish the line.
|
void
|
println(char[] x)
Print an array of characters, and then finish the line.
|
void
|
println(String x)
Print a String, and then finish the line.
|
void
|
println(Object x)
Print an Object, and then finish the line.
|
void
|
setError()
Indicate that an error has occurred.
|
void
|
write(int c)
Write a single character.
|
void
|
write(char[] buf,
int off,
int len)
Write a portion of an array of characters.
|
void
|
write(char[] buf)
Write an array of characters.
|
void
|
write(String s,
int off,
int len)
Write a portion of a string.
|
void
|
write(String s)
Write a string.
|
Methods inherited from class java.lang.Object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PrintWriter
public PrintWriter(Writer out)
- Create a new PrintWriter, without automatic line flushing.
- Parameters:
out
- A character-output stream
PrintWriter
public PrintWriter(Writer out,
boolean autoFlush)
- Create a new PrintWriter.
- Parameters:
out
- A character-output stream
autoFlush
- A boolean; if true, the println() methods will flush
the output buffer
PrintWriter
public PrintWriter(OutputStream out)
- Create 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 character encoding.
- Parameters:
out
- An output stream
- See Also:
- OutputStreamWriter(java.io.OutputStream)
PrintWriter
public PrintWriter(OutputStream out,
boolean autoFlush)
- Create a new PrintWriter from an existing OutputStream. This
convenience constructor creates the necessary intermediate
OutputStreamWriter, which will convert characters into bytes using the
default character encoding.
- Parameters:
out
- An output stream
autoFlush
- A boolean; if true, the println() methods will flush
the output buffer
- See Also:
- OutputStreamWriter(java.io.OutputStream)
flush
public void flush()
- Flush the stream.
- Overrides:
- flush in class Writer
close
public void close()
- Close the stream.
- Overrides:
- close in class Writer
checkError
public boolean checkError()
- Flush the stream and check its error state. Errors are cumulative;
once the stream encounters an error, this routine will return true on
all successive calls.
- Returns:
- True if the print stream has encountered an error, either on the
underlying output stream or during a format conversion.
setError
protected void setError()
- Indicate that an error has occurred.
write
public void write(int c)
- Write a single character.
- Overrides:
- write in class Writer
write
public void write(char[] buf,
int off,
int len)
- Write a portion of an array of characters.
- Overrides:
- write in class Writer
write
public void write(char[] buf)
- Write an array of characters. This method cannot be inherited from the
Writer class because it must suppress I/O exceptions.
- Overrides:
- write in class Writer
write
public void write(String s,
int off,
int len)
- Write a portion of a string.
- Overrides:
- write in class Writer
write
public void write(String s)
- Write a string. This method cannot be inherited from the Writer class
because it must suppress I/O exceptions.
- Overrides:
- write in class Writer
print
public void print(boolean b)
- Print a boolean.
print
public void print(char c)
- Print a character.
print
public void print(int i)
- Print an integer.
print
public void print(long l)
- Print a long.
print
public void print(float f)
- Print a float.
print
public void print(double d)
- Print a double.
print
public void print(char[] s)
- Print an array of chracters.
print
public void print(String s)
- Print a String.
print
public void print(Object obj)
- Print an object.
println
public void println()
- Finish the line.
println
public void println(boolean x)
- Print a boolean, and then finish the line.
println
public void println(char x)
- Print a character, and then finish the line.
println
public void println(int x)
- Print an integer, and then finish the line.
println
public void println(long x)
- Print a long, and then finish the line.
println
public void println(float x)
- Print a float, and then finish the line.
println
public void println(double x)
- Print a double, and then finish the line.
println
public void println(char[] x)
- Print an array of characters, and then finish the line.
println
public void println(String x)
- Print a String, and then finish the line.
println
public void println(Object x)
- Print an Object, and then finish the line.
Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.