Documentation  › java.io  › PrintStream
 
 


  PrintStream
  public

  Inherits From:   FilterOutputStream : OutputStream : Object
  Conforms To:   none
  Declared In:   java.io


Class Description
 
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 PrintWriter class should be used in situations that require writing characters rather than bytes.



Class Variables
 
None declared in this class.


Instance Variables
 
None declared in this class.


Constructors
 
PrintStream
public PrintStream( OutputStream out )

Create a new print stream. This stream will not flush automatically.


PrintStream
public PrintStream( OutputStream out, boolean autoFlush )

Create a new print stream.


PrintStream
public PrintStream( OutputStream out, boolean autoFlush, String encoding ) throws UnsupportedEncodingException

Create a new print stream.


Class Methods
 
None declared in this class.


Instance Methods
 
checkError
public boolean checkError( )

Flush the stream and check its error state. The internal error state is set to 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.


close
public void close( )

Close the stream. This is done by flushing the stream and then closing the underlying output stream.


flush
public void flush( )

Flush the stream. This is done by writing any buffered output bytes to the underlying output stream and then flushing that stream.


print
public void print( boolean b )

Print a boolean value. The string produced by valueOf(boolean) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.


print
public void print( char c )

Print a character. The character is translated into one or more bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.


print
public void print( char[] s )

Print an array of characters. The characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.


print
public void print( double d )

Print a double-precision floating-point number. The string produced by valueOf(double) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.


print
public void print( float f )

Print a floating-point number. The string produced by valueOf(float) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.


print
public void print( int i )

Print an integer. The string produced by valueOf(int) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.


print
public void print( long l )

Print a long integer. The string produced by valueOf(long) is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.


print
public void print( Object obj )

Print an object. The string produced by the valueOf(Object) method is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.


print
public void print( String s )

Print a string. If the argument is null then the string "null" is printed. Otherwise, the string's characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the write(int) method.


println
public void println( )

Terminate the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').


println
public void println( boolean x )

Print a boolean and then terminate the line. This method behaves as though it invokes print(boolean) and then println().


println
public void println( char x )

Print a character and then terminate the line. This method behaves as though it invokes print(char) and then println().


println
public void println( char[] x )

Print an array of characters and then terminate the line. This method behaves as though it invokes print(char[]) and then println().


println
public void println( double x )

Print a double and then terminate the line. This method behaves as though it invokes print(double) and then println().


println
public void println( float x )

Print a float and then terminate the line. This method behaves as though it invokes print(float) and then println().


println
public void println( int x )

Print an integer and then terminate the line. This method behaves as though it invokes print(int) and then println().


println
public void println( long x )

Print a long and then terminate the line. This method behaves as though it invokes print(long) and then println().


println
public void println( Object x )

Print an Object and then terminate the line. This method behaves as though it invokes print(Object) and then println().


println
public void println( String x )

Print a String and then terminate the line. This method behaves as though it invokes print(String) and then println().


setError
protected void setError( )

Set the error state of the stream to true.


write
public void write( byte[] buf, int off, int len )

Write len bytes from the specified byte array starting at offset off to this stream. If automatic flushing is enabled then the flush method will be invoked.

Note that the bytes will be written as given; to write characters that will be translated according to the platform's default character encoding, use the print(char) or println(char) methods.


write
public void write( int b )

Write the specified byte to this stream. If the byte is a newline and automatic flushing is enabled then the 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.



Known Subclasses
 
None.



 
 
  dydoc
  3/9/05