All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.io.PrintStream

java.lang.Object
   |
   +----java.io.OutputStream
           |
           +----java.io.FilterOutputStream
                   |
                   +----java.io.PrintStream

public class PrintStream
extends FilterOutputStream
A print stream implements an output stream filter that provides convenient methods for printing types other than bytes and arrays of bytes.

In addition, the print stream overrides many of the InputStream methods so as not to throw an IOException. Instead, an I/O exception causes an internal flag to be set, which the application can check by a call to the checkError method.

Only the lower eight bits of any 16-bit quantity are printed to the stream.

An application can specify at creation time whether a print stream should be flushed every time a newline character is written.

Here are some examples of the use of a print stream:

     System.out.println("Hello world!");
     System.out.print("x = ");
     System.out.println(x);
     System.out.println("y = " + y);
 

Note: This class is provided primarily for use in debugging, and for compatibility with existing code. New code should use the PrintWriter class.

See Also:
checkError, PrintWriter

Constructor Index

 o PrintStream(OutputStream)
Constructs a new print stream that writes its output to the specified underlying output stream. Deprecated.
 o PrintStream(OutputStream, boolean)
Constructs a new print stream that writes its output to the specified underlying output stream. Deprecated.

Method Index

 o checkError()
Flushes this print stream's underlying output stream, and tests if there has been an error on the underlying output stream.
 o close()
Closes this print stream and releases any resources associated with the underlying output stream.
 o flush()
Flushes this print stream.
 o print(boolean)
Prints the string "true" to the underlying output stream if the value of the boolean argument is true; otherwise, prints the string "false" to the underlying output stream.
 o print(char)
Prints the low eight bits of the character argument to this print stream's underlying output stream.
 o print(char[])
Prints the low eight bits of each of the characters in the character array to this print stream's underlying output stream.
 o print(double)
Prints the string representation of the double to this print stream's underlying output stream.
 o print(float)
Prints the string representation of the float to this print stream's underlying output stream.
 o print(int)
Prints the string representation of the int to this print stream's underlying output stream.
 o print(long)
Prints the string representation of the long to this print stream's underlying output stream.
 o print(Object)
Prints the string representation of the Object to this print stream's underlying output stream.
 o print(String)
If the string argument is null, the string "null" is printed to this print stream's underlying output stream.
 o println()
Prints a newline character to this print stream's underlying output stream.
 o println(boolean)
Prints the string "true" followed by a newline character to this print stream's underlying output stream if the value of the boolean argument is true; otherwise prints the string "false" followed by a newline character to the underlying output stream.
 o println(char)
Prints the low eight bits of the character argument followed by a newline character to this print stream's underlying output stream.
 o println(char[])
Prints the low eight bits of each of the characters in the character array, followed by a newline character, to this print stream's underlying output stream.
 o println(double)
Prints the string representation of the double followed by a newline to this print stream's underlying output stream.
 o println(float)
Prints the string representation of the float followed by a newline to this print stream's underlying output stream.
 o println(int)
Prints the string representation of the int followed by a newline to this print stream's underlying output stream.
 o println(long)
Prints the string representation of the long followed by a newline to this print stream's underlying output stream.
 o println(Object)
Prints the string representation of the Object followed by a newline to this print stream's underlying output stream.
 o println(String)
If the string argument is null, the string "null" followed by a newline character is printed to this print stream's underlying output stream.
 o setError()
Indicates that an error has occurred.
 o write(byte[], int, int)
Writes a portion of the specified byte array, blocking if necessary.
 o write(int)
Writes the specified byte to this print stream.

Constructors

 o PrintStream
    method PrintStream(out=OutputStream) public 
Note: PrintStream() is deprecated. As of JDK 1.1, the preferred way to print text is using the PrintWriter class. Consider replacing code of the form:
    PrintStream p = new PrintStream(out);
with code of the form:
    PrintWriter p = new PrintWriter(out);

Constructs a new print stream that writes its output to the specified underlying output stream.

Parameters:
out - the underlying output stream.
See Also:
out, PrintWriter
 o PrintStream
    method PrintStream(out=OutputStream, -
                       autoFlush=boolean) public 
Note: PrintStream() is deprecated. As of JDK 1.1, the preferred way to print text is using the PrintWriter class. Consider replacing code of the form:
    PrintStream p = new PrintStream(out, autoFlush);
with code of the form:
    PrintWriter p = new PrintWriter(out, autoFlush);

Constructs a new print stream that writes its output to the specified underlying output stream. In addition, if the autoflush flag is true, then the underlying output stream's flush method is called any time a newline character is printed.

Parameters:
out - the underlying output stream.
autoflush - if true, the stream automatically flushes its output when a newline character is printed.
See Also:
out, PrintWriter

Methods

 o flush
    method flush()  public     
Flushes this print stream. This forces any buffered output bytes to be written to the underlying stream.

The flush method of PrintStream calls the flush method of its underlying output stream. However, if that flush method throws an IOException, this method catches that exception and indicates, instead, that the underlying stream has gotten an error

Overrides:
flush in class FilterOutputStream
See Also:
out, flush, checkError
 o close
    method close()  public     
Closes this print stream and releases any resources associated with the underlying output stream.

The close method of PrintStream calls the close method of its underlying output stream. However, if that close method throws an IOException, this method catches that exception and indicates, instead, that the underlying stream has gotten an error,

Overrides:
close in class FilterOutputStream
See Also:
out, close, checkError
 o checkError
    method checkError() returns boolean public     
Flushes this print stream's underlying output stream, and tests if there has been an error on the underlying output stream.

Errors are cumulative; once the print stream has encounted an error, this method will continue to return true on all successive calls.

Returns:
true if the print stream has ever encountered an error on the output stream or during a format conversion; false otherwise.
 o setError
    method setError()  Inheritable     
Indicates that an error has occurred.

 o write
    method write(b=int)  public     
Writes the specified byte to this print stream.

The write method of PrintStream calls the write method of its underlying stream. In addition, if the character is a newline character and autoflush is turned on, then the print stream's flush method is called.

If any IOException is thrown while writing the byte, the exception is caught, and instead an internal error flag is set; the value of the flag can be checked by a call to the checkError method.

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 or println methods.

Parameters:
b - the byte.
Overrides:
write in class FilterOutputStream
See Also:
print, println
 o write
    method write(buf=byte[], -
                 off=int, -
                 len=int)  public     
Writes a portion of the specified byte array, blocking if necessary. Writes len bytes from the specified byte array starting at offset off to this print stream's underlying output stream.

Parameters:
buf - the data.
off - the start offset in the data.
len - the number of bytes to write.
Overrides:
write in class FilterOutputStream
See Also:
out
 o print
    method print(b=boolean)  public     
Prints the string "true" to the underlying output stream if the value of the boolean argument is true; otherwise, prints the string "false" to the underlying output stream.

Parameters:
b - a boolean to be printed.
See Also:
out
 o print
    method print(c=char)  public     
Prints the low eight bits of the character argument to this print stream's underlying output stream.

Parameters:
c - a char to be printed.
See Also:
out
 o print
    method print(i=int)  public     
Prints the string representation of the int to this print stream's underlying output stream. The string representation is identical to the one returned by the toString method of class Integer with the argument i.

Parameters:
i - an int to be printed.
See Also:
out, toString
 o print
    method print(l=long)  public     
Prints the string representation of the long to this print stream's underlying output stream. The string representation is identical to the one returned by the toString method of class Long with the argument l.

Parameters:
l - a long to be printed.
See Also:
out, toString
 o print
    method print(f=float)  public     
Prints the string representation of the float to this print stream's underlying output stream. The string representation is identical to the one returned by the toString method of class Float with the argument f.

Parameters:
f - a float to be printed.
See Also:
out, toString
 o print
    method print(d=double)  public     
Prints the string representation of the double to this print stream's underlying output stream. The string representation is identical to the one returned by the toString method of class Double with the argument d.

Parameters:
d - a double to be printed.
See Also:
out, toString
 o print
    method print(s=char[])  public     
Prints the low eight bits of each of the characters in the character array to this print stream's underlying output stream.

Parameters:
s - an array of chars to be printed.
See Also:
out
 o print
    method print(s=String)  public     
If the string argument is null, the string "null" is printed to this print stream's underlying output stream. Otherwise, the low eight bits of each of the characters in the string is printed to the underlying output stream.

Parameters:
s - a string to be printed.
See Also:
out
 o print
    method print(obj=Object)  public     
Prints the string representation of the Object to this print stream's underlying output stream. The string representation is identical to the one returned by calling the Object argument's toString method.

Parameters:
obj - an Object to be printed.
See Also:
out, toString
 o println
    method println()  public     
Prints a newline character to this print stream's underlying output stream. The line-separator string is defined by the system property line.separator, and is not necessarily a single newline ('\n') character.

See Also:
out
 o println
    method println(x=boolean)  public     
Prints the string "true" followed by a newline character to this print stream's underlying output stream if the value of the boolean argument is true; otherwise prints the string "false" followed by a newline character to the underlying output stream.

Parameters:
x - a boolean to be printed.
See Also:
out, print
 o println
    method println(x=char)  public     
Prints the low eight bits of the character argument followed by a newline character to this print stream's underlying output stream.

Parameters:
x - a char to be printed.
See Also:
out, print
 o println
    method println(x=int)  public     
Prints the string representation of the int followed by a newline to this print stream's underlying output stream. The string representation is identical to the one returned by the toString method of class Integer with the argument i.

Parameters:
x - an int to be printed.
See Also:
out, print, toString
 o println
    method println(x=long)  public     
Prints the string representation of the long followed by a newline to this print stream's underlying output stream. The string representation is identical to the one returned by the toString method of class Long with the argument l.

Parameters:
x - a long to be printed.
See Also:
out, print, toString
 o println
    method println(x=float)  public     
Prints the string representation of the float followed by a newline to this print stream's underlying output stream. The string representation is identical to the one returned by the toString method of class Integer with the argument f.

Parameters:
x - a float to be printed.
See Also:
out, print, toString
 o println
    method println(x=double)  public     
Prints the string representation of the double followed by a newline to this print stream's underlying output stream. The string representation is identical to the one returned by the toString method of class Double with the argument d.

Parameters:
x - a double to be printed.
See Also:
out, print, toString
 o println
    method println(x=char[])  public     
Prints the low eight bits of each of the characters in the character array, followed by a newline character, to this print stream's underlying output stream.

Parameters:
x - an array of characters to be printed.
See Also:
out, print
 o println
    method println(x=String)  public     
If the string argument is null, the string "null" followed by a newline character is printed to this print stream's underlying output stream. Otherwise, the low 8 bits of each of the characters in the string, followed by a newline character, is printed to the underlying output stream.

Parameters:
x - a string to be printed.
See Also:
out, print
 o println
    method println(x=Object)  public     
Prints the string representation of the Object followed by a newline to this print stream's underlying output stream. The string representation is identical to the one returned by calling the Object argument's toString method.

Parameters:
x - an Object to be printed.
See Also:
out, print, toString

All Packages  Class Hierarchy  This Package  Previous  Next  Index