All Packages  Class Hierarchy  This Package  Previous  Next  Index

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().


Constructor Index

 o PrintWriter(OutputStream)
Create a new PrintWriter, without automatic line flushing, from an existing OutputStream.
 o PrintWriter(OutputStream, boolean)
Create a new PrintWriter from an existing OutputStream.
 o PrintWriter(Writer)
Create a new PrintWriter, without automatic line flushing.
 o PrintWriter(Writer, boolean)
Create a new PrintWriter.

Method Index

 o checkError()
Flush the stream and check its error state.
 o close()
Close the stream.
 o flush()
Flush the stream.
 o print(boolean)
Print a boolean.
 o print(char)
Print a character.
 o print(char[])
Print an array of chracters.
 o print(double)
Print a double.
 o print(float)
Print a float.
 o print(int)
Print an integer.
 o print(long)
Print a long.
 o print(Object)
Print an object.
 o print(String)
Print a String.
 o println()
Finish the line.
 o println(boolean)
Print a boolean, and then finish the line.
 o println(char)
Print a character, and then finish the line.
 o println(char[])
Print an array of characters, and then finish the line.
 o println(double)
Print a double, and then finish the line.
 o println(float)
Print a float, and then finish the line.
 o println(int)
Print an integer, and then finish the line.
 o println(long)
Print a long, and then finish the line.
 o println(Object)
Print an Object, and then finish the line.
 o println(String)
Print a String, and then finish the line.
 o setError()
Indicate that an error has occurred.
 o write(char[])
Write an array of characters.
 o write(char[], int, int)
Write a portion of an array of characters.
 o write(int)
Write a single character.
 o write(String)
Write a string.
 o write(String, int, int)
Write a portion of a string.

Constructors

 o PrintWriter
 public PrintWriter(Writer out)
Create a new PrintWriter, without automatic line flushing.

Parameters:
out - A character-output stream
 o 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
 o 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
 o 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

Methods

 o flush
 public void flush()
Flush the stream.

Overrides:
flush in class Writer
 o close
 public void close()
Close the stream.

Overrides:
close in class Writer
 o 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.
 o setError
 protected void setError()
Indicate that an error has occurred.

 o write
 public void write(int c)
Write a single character.

Overrides:
write in class Writer
 o write
 public void write(char buf[],
                   int off,
                   int len)
Write a portion of an array of characters.

Overrides:
write in class Writer
 o 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
 o write
 public void write(String s,
                   int off,
                   int len)
Write a portion of a string.

Overrides:
write in class Writer
 o 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
 o print
 public void print(boolean b)
Print a boolean.

 o print
 public void print(char c)
Print a character.

 o print
 public void print(int i)
Print an integer.

 o print
 public void print(long l)
Print a long.

 o print
 public void print(float f)
Print a float.

 o print
 public void print(double d)
Print a double.

 o print
 public void print(char s[])
Print an array of chracters.

 o print
 public void print(String s)
Print a String.

 o print
 public void print(Object obj)
Print an object.

 o println
 public void println()
Finish the line.

 o println
 public void println(boolean x)
Print a boolean, and then finish the line.

 o println
 public void println(char x)
Print a character, and then finish the line.

 o println
 public void println(int x)
Print an integer, and then finish the line.

 o println
 public void println(long x)
Print a long, and then finish the line.

 o println
 public void println(float x)
Print a float, and then finish the line.

 o println
 public void println(double x)
Print a double, and then finish the line.

 o println
 public void println(char x[])
Print an array of characters, and then finish the line.

 o println
 public void println(String x)
Print a String, and then finish the line.

 o println
 public void println(Object x)
Print an Object, and then finish the line.


All Packages  Class Hierarchy  This Package  Previous  Next  Index