CHAPTER 22: The Package java.io Previous
Previous
Java Language
Java Language
Index
Index
Next
Next

22.22 The Class java.io.PrintStream

22.22.1 PrintStream , 22.22.2 PrintStream , 22.22.3 write , 22.22.4 write , 22.22.5 flush , 22.22.6 close , 22.22.7 checkError , 22.22.8 print , 22.22.9 print , 22.22.10 print , 22.22.11 print , 22.22.12 print , 22.22.13 print , 22.22.14 print , 22.22.15 print , 22.22.16 print , 22.22.17 println , 22.22.18 println , 22.22.19 println , 22.22.20 println , 22.22.21 println , 22.22.22 println , 22.22.23 println , 22.22.24 println , 22.22.25 println , 22.22.26 println

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 by the checkError method. Optionally, a PrintStream can be created so as to "autoflush"; this means that after an array of bytes is written, or after a single byte equal to '\n' is written, the flush method is automatically invoked.

public class PrintStream extends FilterOutputStream {
	public PrintStream(OutputStream out);
	public PrintStream(OutputStream out, boolean autoflush);
	public void write(int b);
	public void write(byte[] b, int off, int len)
		throws NullPointerException, IndexOutOfBoundsException;
	public void flush();
	public void close();
	public boolean checkError();
	public void print(Object obj);
	public void print(String s);
	public void print(char[] s) throws NullPointerException;
	public void print(char c);
	public void print(int i);
	public void print(long l);
	public void print(float f);
	public void print(double d);
	public void print(boolean b);
	public void println();
	public void println(Object obj);
	public void println(String s);
	public void println(char[] s) throws NullPointerException;
	public void println(char c);
	public void println(int i);
	public void println(long l);
	public void println(float f);
	public void println(double d);
	public void println(boolean b);
}


22.22.1 PrintStream

public PrintStream(OutputStream out)

This constructor initializes a newly created PrintStream by saving its argument, the output stream out, for later use. This stream will not autoflush.


22.22.2 PrintStream

public PrintStream(OutputStream out, boolean autoflush)

This constructor initializes a newly created PrintStream by saving its argument, the output stream out, for later use. This stream will autoflush if and only if autoflush is true.


22.22.3 write

public void write(int b)

See the general contract of the write method of OutputStream (S22.15.1).

Overrides the write method of FilterOutputStream (S22.19.3).


22.22.4 write

public void write(byte[] b, int off, int len)
	throws NullPointerException,       IndexOutOfBoundsException

See the general contract of the write method of OutputStream (S22.15.3).

Overrides the write method of FilterOutputStream (S22.19.5).


22.22.5 flush

public void flush()

See the general contract of the flush method of OutputStream (S22.15.4).

Overrides the flush method of FilterOutputStream (S22.19.6).


22.22.6 close

public void close()

See the general contract of the close method of OutputStream (S22.15.5).

Overrides the close method of FilterOutputStream (S22.19.7).


22.22.7 checkError

public boolean checkError()

The result is true if and only if this output stream has ever encountered any kind of trouble-that is, if any operation on the contained output stream has ever resulted in an IOException other than an InterruptedIOException. If an operation on the contained output stream throws an InterruptedIOException, then the PrintStream class converts the exception back to an interrupt by doing:

Thread.currentThread().interrupt();

or the equivalent.


22.22.8 print

public void print(Object obj)

The low-order bytes of the characters in the String that would be produced by String.valueOf(obj) (S20.12.38) are written, in order, to the contained output stream in exactly the manner of the write method (S22.22.3).


22.22.9 print

public void print(String s)

The low-order bytes of the characters in the string s are written, in order, to the contained output stream in exactly the manner of the write method (S22.22.3). If s is null, then the low-order bytes of the four characters n, u, l, l are written to the contained output stream.


22.22.10 print

public void print(char[] s) throws NullPointerException

The low-order bytes of the characters in the character array s are written, in order, to the contained output stream in exactly the manner of the write method (S22.22.3).

If s is null, a NullPointerException is thrown.


22.22.11 print

public void print(boolean b)

The low-order bytes of the characters in the String that would be produced by String.valueOf(b) (S20.12.41) as a string are written, in order, to the contained output stream in exactly the manner of the write method (S22.22.3).


22.22.12 print

public void print(char c)

The low-order byte of the character c is written to the contained output stream in exactly the manner of the write method (S22.22.3).


22.22.13 print

public void print(int i)

The low-order bytes of the characters in the String that would be produced by String.valueOf(i) (S20.12.43) as a string are written, in order, to the contained output stream in exactly the manner of the write method (S22.22.3).


22.22.14 print

public void print(long l)

The low-order bytes of the characters in the String that would be produced by String.valueOf(l) (S20.12.44) as a string are written, in order, to the contained output stream in exactly the manner of the write method (S22.22.3).


22.22.15 print

public void print(float f)

The low-order bytes of the characters in the String that would be produced by String.valueOf(f) (S20.12.45) as a string are written, in order, to the contained output stream in exactly the manner of the write method (S22.22.3).


22.22.16 print

public void print(double d)

The low-order bytes of the characters in the String that would be produced by String.valueOf(d) (S20.12.46) as a string are written, in order, to the contained output stream in exactly the manner of the write method (S22.22.3).


22.22.17 println

public void println()

The low-order byte of the newline character '\n' is written to the contained output stream in exactly the manner of the write method (S22.22.3).


22.22.18 println

public void println(Object obj)

This is exactly the same as print(obj) (S22.22.8) followed by writing the low- order byte of the newline character '\n' to the contained output stream.


22.22.19 println

public void println(String s)

This is exactly the same as print(s) (S22.22.9) followed by writing the low- order byte of the newline character '\n' to the contained output stream.


22.22.20 println

public void println(char[] s) throws NullPointerException

This is exactly the same as print(s) (S22.22.10) followed by writing the low- order byte of the newline character '\n' to the contained output stream.

If s is null, a NullPointerException is thrown.


22.22.21 println

public void println(boolean b)

This is exactly the same as print(b) (S22.22.11) followed by writing the low- order byte of the newline character '\n' to the contained output stream.


22.22.22 println

public void println(char c)

This is exactly the same as print(c) (S22.22.12) followed by writing the low- order byte of the newline character '\n' to the contained output stream.


22.22.23 println

public void println(int i)

This is exactly the same as print(i) (S22.22.13) followed by writing the low- order byte of the newline character '\n' to the contained output stream.


22.22.24 println

public void println(long l)

This is exactly the same as print(l) (S22.22.14) followed by writing the low- order byte of the newline character '\n' to the contained output stream.


22.22.25 println

public void println(float f)

This is exactly the same as print(f) (S22.22.15) followed by writing the low- order byte of the newline character '\n' to the contained output stream.


22.22.26 println

public void println(double d)

This is exactly the same as print(d) (S22.22.16) followed by writing the low- order byte of the newline character '\n' to the contained output stream.

Top© 1996 Sun Microsystems, Inc. All rights reserved.