java.io
Class PrintStream

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

public class PrintStream
extends FilterOutputStream

This class implements an output stream that has additional methods for printing. You can specify that the stream should be flushed every time a newline character is written.

The top byte of 16 bit characters is discarded.

Example:

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


Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
PrintStream(OutputStream out)
          Creates a new PrintStream.
PrintStream(OutputStream out, boolean autoflush)
          Creates a new PrintStream, with auto flushing.
 
Method Summary
 boolean checkError()
          Flushes the print stream and returns whether or not there was an error on the output stream.
 void close()
          Closes the stream.
 void flush()
          Flushes the stream.
 void print(boolean b)
          Prints a boolean.
 void print(char c)
          Prints an character.
 void print(char[] s)
          Prints an array of characters.
 void print(double d)
          Prints a double.
 void print(float f)
          Prints a float.
 void print(int i)
          Prints an integer.
 void print(long l)
          Prints a long.
 void print(Object obj)
          Prints an object.
 void print(String s)
          Prints a String.
 void println()
          Prints a newline.
 void println(boolean b)
          Prints a boolean followed by a newline.
 void println(char c)
          Prints a character followed by a newline.
 void println(char[] s)
          Prints an array of characters followed by a newline.
 void println(double d)
          Prints a double followed by a newline.
 void println(float f)
          Prints a float followed by a newline.
 void println(int i)
          Prints an integer followed by a newline.
 void println(long l)
          Prints a long followed by a newline.
 void println(Object obj)
          Prints an object followed by a newline.
 void println(String s)
          Prints a string followed by a newline.
 void write(byte[] b, int off, int len)
          Writes a sub array of bytes.
 void write(int b)
          Writes a byte.
 
Methods inherited from class java.io.FilterOutputStream
write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PrintStream

public PrintStream(OutputStream out)
Creates a new PrintStream.

Parameters:
out - the output stream

PrintStream

public PrintStream(OutputStream out,
                   boolean autoflush)
Creates a new PrintStream, with auto flushing.

Parameters:
out - the output stream
autoflush - if true the stream automatically flushes its output when a newline character is printed
Method Detail

write

public void write(int b)
Writes a byte. This method will block until the byte is actually written.

Overrides:
write in class FilterOutputStream
Parameters:
b - the byte
Throws:
IOException - If an I/O error has occurred.

write

public void write(byte[] b,
                  int off,
                  int len)
Writes a sub array of bytes.

Overrides:
write in class FilterOutputStream
Parameters:
b - the data to be written
off - the start offset in the data
len - the number of bytes that are written
Throws:
IOException - If an I/O error has occurred.

flush

public void flush()
Flushes the stream. This will write any buffered output bytes.

Overrides:
flush in class FilterOutputStream

close

public void close()
Closes the stream.

Overrides:
close in class FilterOutputStream

checkError

public boolean checkError()
Flushes the print stream and returns whether or not there was an error on the output stream. Errors are cumulative; once the print stream encounters an error this routine will continue to return true on all successive calls.

Returns:
true if the print stream has ever encountered an error on the output stream.

print

public void print(Object obj)
Prints an object.

Parameters:
obj - the object to be printed

print

public void print(String s)
Prints a String.

Parameters:
s - the String to be printed

print

public void print(char[] s)
Prints an array of characters.

Parameters:
s - the array of chars to be printed

print

public void print(char c)
Prints an character.

Parameters:
c - the character to be printed

print

public void print(int i)
Prints an integer.

Parameters:
i - the integer to be printed

print

public void print(long l)
Prints a long.

Parameters:
l - the long to be printed.

print

public void print(float f)
Prints a float.

Parameters:
f - the float to be printed

print

public void print(double d)
Prints a double.

Parameters:
d - the double to be printed

print

public void print(boolean b)
Prints a boolean.

Parameters:
b - the boolean to be printed

println

public void println()
Prints a newline.


println

public void println(Object obj)
Prints an object followed by a newline.

Parameters:
obj - the object to be printed

println

public void println(String s)
Prints a string followed by a newline.

Parameters:
s - the String to be printed

println

public void println(char[] s)
Prints an array of characters followed by a newline.

Parameters:
s - the array of characters to be printed

println

public void println(char c)
Prints a character followed by a newline.

Parameters:
c - the character to be printed

println

public void println(int i)
Prints an integer followed by a newline.

Parameters:
i - the integer to be printed

println

public void println(long l)
Prints a long followed by a newline.

Parameters:
l - the long to be printed

println

public void println(float f)
Prints a float followed by a newline.

Parameters:
f - the float to be printed

println

public void println(double d)
Prints a double followed by a newline.

Parameters:
d - the double to be printed

println

public void println(boolean b)
Prints a boolean followed by a newline.

Parameters:
b - the boolean to be printed