Packages  This Package  Prev  Next  Index  

§2.18 Class PrintStream

public  class  java.io.PrintStream
    extends  java.io.FilterOutputStream  (I-§2.12)
{
        // Constructors
    public PrintStream(OutputStream  out);	§2.18.1
    public PrintStream(OutputStream  out, boolean  autoflush);	§2.18.2

        // Methods
    public boolean checkError();	§2.18.3
    public void close();	§2.18.4
    public void flush();	§2.18.5
    public void print(boolean  b);	§2.18.6
    public void print(char  c);	§2.18.7
    public void print(char  s[]);	§2.18.8
    public void print(double  d);	§2.18.9
    public void print(float  f);	§2.18.10
    public void print(int  i);	§2.18.11
    public void print(long  l);	§2.18.12
    public void print(Object  obj);	§2.18.13
    public void print(String  s);	§2.18.14
    public void println();	§2.18.15
    public void println(boolean  b);	§2.18.16
    public void println(char  c);	§2.18.17
    public void println(char  s[]);	§2.18.18
    public void println(double  d);	§2.18.19
    public void println(float  f);	§2.18.20
    public void println(int  i);	§2.18.21
    public void println(long  l);	§2.18.22
    public void println(Object  obj);	§2.18.23
    public void println(String  s);	§2.18.24
    public void write(byte  b[], int  off, int  len);	§2.18.25
    public void write(int  b);	§2.18.26
}
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 (I-§2.18.3).

Only the lower 8 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:


Constructors

PrintStream

public PrintStream(OutputStream out)
Constructs a new print stream that writes its output to the specified underlying output stream (I-§2.12.1).

Parameters:
out - the underlying output stream

PrintStream

public
PrintStream(OutputStream out, boolean autoflush)
Constructs a new print stream that writes its output to the specified underlying output stream (I-§2.12.1). 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

Methods

checkError

public boolean checkError()
Flushes this print stream's underlying output stream, and returns a boolean indicating 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; false otherwise.

close

public void close()
Closes this print stream and releases any resources associated with the underlying output stream.
The close method of PrintStream calls the close method (I-§2.15.2) of its underlying output stream (I-§2.12.1). However, if that close method throws an IOException, this method catches that exception and indicates, instead, that the underlying stream has gotten an error (see I-§2.18.3).

Overrides:
close in class FilterOutputStream (I-§2.12.3).

flush

public void flush()
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 (I-§2.15.3) of its underlying output stream (I-§2.12.1). However, if that flush method throws an IOException, this method catches that exception and indicates, instead, that the underlying stream has gotten an error (see I-§2.18.3).

Overrides:
flush in class FilterOutputStream (I-§2.12.4).

print

public void print(boolean b)
Prints the string "true" to the underlying output stream (I-§2.12.1) 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

print

public void print(char c)
Prints the low eight bits of the character argument to this print stream's underlying output stream (I-§2.12.1).

Parameters:
c - a char to be printed

print

public void print(char s[])
Prints the low eight bits of each of the characters in the character array to this print stream's underlying output stream (I-§2.12.1).

Parameters:
s - an array of chars to be printed

print

public void print(double d)
Prints the string representation of the double to this print stream's underlying output stream (I-§2.12.1). The string representation is identical to the one returned by the toString method (I-§1.6.21) of class Double with the argument d.

Parameters:
d - a double to be printed

print

public void print(float f)
Prints the string representation of the float to this print stream's underlying output stream (I-§2.12.1). The string representation is identical to the one returned by the toString method (I-§1.7.22) of class Float with the argument f.

Parameters:
f - a float to be printed

print

public void print(int i)
Prints the string representation of the int to this print stream's underlying output stream (I-§2.12.1). The string representation is identical to the one returned by the toString method (I-§1.8.20) of class Integer with the argument i.

Parameters:
i - an int to be printed

print

public void print(long l)
Prints the string representation of the long to this print stream's underlying output stream (I-§2.12.1). The string representation is identical to the one returned by the toString method (I-§1.9.20) of class Long with the argument l.

Parameters:
l - a long to be printed.

print

public void print(Object obj)
Prints the string representation of the Object to this print stream's underlying output stream (I-§2.12.1). The string representation is identical to the one returned by calling the Object argument's toString method (I-§1.12.9).

Parameters:
obj - an Object to be printed

print

public void print(String s)
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 (I-§2.12.1).

Parameters:
s - a String to be printed

println

public void println()
Prints a newline character to this print stream's underlying output stream (I-§2.12.1).

println

public void println(boolean b)
Prints the string "true" followed by a newline character to this print stream's underlying output stream if the value of the boolean argumentis true; otherwise, prints the string "false" followed by a newline character to the underlying output stream (I-§2.12.1).

Parameters:
b - a boolean to be printed

println

public void println(char c)
Prints the low eight bits of the character argument followed by a newline characer to this print stream's underlying output stream (I-§2.12.1).

Parameters:
c - a char to be printed

println

public void println(char s[])
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 (I-§2.12.1).

Parameters:
s - an array of characters to be printed

println

public void println(double d)
Prints the string representation of the double followed by a newline to this print stream's underlying output stream (I-§2.12.1). The string representation is identical to the one returned by the toString method (I-§1.6.21) of class Double with the argument d.

Parameters:
d - a double to be printed

println

public void println(float f)
Prints the string representation of the float followed by a newline to this print stream's underlying output stream (I-§2.12.1). The string representation is identical to the one returned by the toString method (I-§1.8.20) of class Integer with the argument f.

Parameters:
f - a float to be printed

println

public void println(int i)
Prints the string representation of the int followed by a newline to this print stream's underlying output stream (I-§2.12.1). The string representation is identical to the one returned by the toString method (I-§1.8.20) of class Integer with the argument i.

Parameters:
i - an int to be printed

println

public void println(long l)
Prints the string representation of the long followed by a newline to this print stream's underlying output stream (I-§2.12.1). The string representation is identical to the one returned by the toString method (I-§1.9.20) of class Long with the argument l.

Parameters:
l - a long to be printed

println

public void println(Object obj)
Prints the string representation of the Object followed by a newline to this print stream's underlying output stream (I-§2.12.1). The string representation is identical to the one returned by calling the Object argument's toString method (I-§1.12.9).

Parameters:
obj - an Object to be printed

println

public void println(String s)
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 eight bits of each of the characters in the string, followed by a newline character, is printed to the underlying output stream (I-§2.12.1).

Parameters:
s - a String to be printed

write

public void write(byte b[], int off, int len)
Writes len bytes from the specified byte array starting at offset off to this print stream's underlying output stream (I-§2.12.1).

Parameters:
b - the data
off - the start offset in the data
len - the number of bytes to write
Overrides:
write in class FilterOutputStream (I-§2.12.6).

write

public void write(int b)
Writes the specified byte to this print stream.
The write method of PrintStream calls the write method of its underlying stream (I-§2.12.1). In addition, if the character is a newline character and autoflush is turned on, then the print stream's flush method (I-§2.18.5) 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 (I-§2.18.3)

Parameters:
b - the byte
Overrides:
write in class FilterOutputStream (I-§2.12.7).

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com