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
Print values and objects to an output stream, using the platform's default character encoding to convert characters into bytes.

If automatic flushing is enabled at creation time, then the stream will be flushed each time a line is terminated or a newline character is written.

Methods in this class never throw I/O exceptions. Client code may inquire as to whether any errors have occurred by invoking the checkError method.

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:
PrintWriter

Constructor Index

 o PrintStream(OutputStream)
Create a new print stream. Deprecated.
 o PrintStream(OutputStream, boolean)
Create a new PrintStream. Deprecated.

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 value.
 o print(char)
Print a character.
 o print(char[])
Print an array of characters.
 o print(double)
Print a double-precision floating-point number.
 o print(float)
Print a floating-point number.
 o print(int)
Print an integer.
 o print(long)
Print a long integer.
 o print(Object)
Print an object.
 o print(String)
Print a string.
 o println()
Finish the current line by writing a line separator.
 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(byte[], int, int)
Write a portion of a byte array, blocking if necessary.
 o write(int)
Write a byte, blocking if necessary.

Constructors

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

Create a new print stream.

Parameters:
out - The output stream to which values and objects will be printed
See Also:
PrintWriter
 o PrintStream
 public PrintStream(OutputStream out,
                    boolean autoFlush)
Note: PrintStream() is deprecated. As of JDK 1.1, the preferred way to print text is via the PrintWriter class. Consider replacing code of the
form   PrintStream p = new PrintStream(out, autoFlush);
with   PrintWriter p = new PrintWriter(out, autoFlush);

Create a new PrintStream.

Parameters:
out - The output stream to which values and objects will be printed
autoFlush - A boolean; if true, the output buffer will be flushed whenever a line is terminated or a newline character ('\n') is written
See Also:
PrintWriter

Methods

 o 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.

Overrides:
flush in class FilterOutputStream
See Also:
flush
 o close
 public void close()
Close the stream. This is done by flushing the stream and then closing the underlying output stream.

Overrides:
close in class FilterOutputStream
See Also:
close
 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 continue to 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, otherwise false.
 o setError
 protected void setError()
Indicate that an error has occurred.

 o write
 public void write(int b)
Write a byte, blocking if necessary. If the character is a newline and automatic flushing is enabled, the stream's flush method will be called.

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.

Parameters:
b - The byte to be written
Overrides:
write in class FilterOutputStream
See Also:
print, println
 o write
 public void write(byte buf[],
                   int off,
                   int len)
Write a portion of a byte array, blocking if necessary.

Parameters:
buf - A byte array
off - Offset from which to start taking bytes
len - Number of bytes to write
Overrides:
write in class FilterOutputStream
 o print
 public void print(boolean b)
Print a boolean value. If the given value is true, then the string "true" is written to the underlying output stream; otherwise, the string "false" is written.

Parameters:
b - The boolean to be printed
 o 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.

Parameters:
c - The char to be printed
 o print
 public void print(int i)
Print an integer. The string printed is the same as that returned by the toString method of the Integer class when invoked on the given int value.

Parameters:
i - The int to be printed
See Also:
toString
 o print
 public void print(long l)
Print a long integer. The string printed is the same as that returned by the toString method of the Long class when invoked on the given long value.

Parameters:
l - The long to be printed
See Also:
toString
 o print
 public void print(float f)
Print a floating-point number. The string printed is the same as that returned by the toString method of the Float class when invoked on the given float value.

Parameters:
f - The float to be printed
See Also:
toString
 o print
 public void print(double d)
Print a double-precision floating-point number. The string printed is the same as that returned by the toString method of the Double class when invoked on the given double value.

Parameters:
d - The double to be printed
See Also:
toString
 o 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.

Parameters:
s - The array of chars to be printed
 o print
 public void print(String s)
Print a string. If the argument is null, the string "null" is written to the underlying output stream. Otherwise, the string's characters are converted into bytes according to the platform's default character encoding.

Parameters:
s - The String to be printed
 o print
 public void print(Object obj)
Print an object. The string printed is the same as that returned by the given object's toString method.

Parameters:
obj - The Object to be printed
See Also:
toString
 o println
 public void println()
Finish the current line by writing a line separator. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').

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

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

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

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

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

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

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

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

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

See Also:
print

All Packages  Class Hierarchy  This Package  Previous  Next  Index