All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----java.io.OutputStream
|
+----java.io.FilterOutputStream
|
+----java.io.PrintStream
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.
"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.
double to
this print stream's underlying output stream.
float to
this print stream's underlying output stream.
int to this
print stream's underlying output stream.
long to this
print stream's underlying output stream.
Object to
this print stream's underlying output stream.
null, the string
"null" is printed to this print stream's underlying
output stream.
"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.
double
followed by a newline to this print stream's underlying output
stream.
float
followed by a newline to this print stream's underlying output
stream.
int followed
by a newline to this print stream's underlying output stream.
long
followed by a newline to this print stream's underlying output
stream.
Object
followed by a newline to this print stream's underlying output
stream.
null, the string
"null" followed by a newline character is printed to
this print stream's underlying output stream.
public PrintStream(OutputStream out)
PrintWriter class. Consider replacing
code of the form:
PrintStream p = new PrintStream(out);
PrintWriter p = new PrintWriter(out);
public PrintStream(OutputStream out,
boolean autoFlush)
PrintWriter class. Consider replacing
code of the form:
PrintStream p = new PrintStream(out, autoFlush);
PrintWriter p = new PrintWriter(out, autoFlush);
autoflush flag is true, then the
underlying output stream's flush method is called any
time a newline character is printed.
true, the stream automatically
flushes its output when a newline character is
printed.
public void flush()
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
public void close()
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,
public boolean checkError()
Errors are cumulative; once the print stream has encounted an
error, this method will continue to return true on
all successive calls.
true if the print stream has ever encountered an
error on the output stream or during a format conversion;
false otherwise.
protected void setError()
public void write(int b)
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.
public void write(byte buf[],
int off,
int len)
len bytes from the specified byte array
starting at offset off to this print stream's
underlying output stream.
public void print(boolean b)
"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.
boolean to be printed.
public void print(char c)
char to be printed.
public void print(int i)
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.
int to be printed.
public void print(long l)
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.
long to be printed.
public void print(float f)
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.
float to be printed.
public void print(double d)
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.
double to be printed.
public void print(char s[])
public void print(String s)
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.
public void print(Object obj)
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.
Object to be printed.
public void println()
line.separator, and is not necessarily a single newline
('\n') character.
public void println(boolean x)
"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.
boolean to be printed.
public void println(char x)
char to be printed.
public void println(int x)
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.
int to be printed.
public void println(long x)
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.
long to be printed.
public void println(float x)
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.
float to be printed.
public void println(double x)
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.
double to be printed.
public void println(char x[])
public void println(String x)
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.
public void println(Object x)
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.
Object to be printed.
All Packages Class Hierarchy This Package Previous Next Index