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
- PrintStream(OutputStream)
- Create a new print stream. Deprecated.
- PrintStream(OutputStream, boolean)
- Create a new PrintStream. Deprecated.
- checkError()
- Flush the stream and check its error state.
- close()
- Close the stream.
- flush()
- Flush the stream.
- print(boolean)
- Print a boolean value.
- print(char)
- Print a character.
- print(char[])
- Print an array of characters.
- print(double)
- Print a double-precision floating-point number.
- print(float)
- Print a floating-point number.
- print(int)
- Print an integer.
- print(long)
- Print a long integer.
- print(Object)
- Print an object.
- print(String)
- Print a string.
- println()
- Finish the current line by writing a line separator.
- println(boolean)
- Print a boolean, and then finish the line.
- println(char)
- Print a character, and then finish the line.
- println(char[])
- Print an array of characters, and then finish the line.
- println(double)
- Print a double, and then finish the line.
- println(float)
- Print a float, and then finish the line.
- println(int)
- Print an integer, and then finish the line.
- println(long)
- Print a long, and then finish the line.
- println(Object)
- Print an Object, and then finish the line.
- println(String)
- Print a String, and then finish the line.
- setError()
- Indicate that an error has occurred.
- write(byte[], int, int)
- Write a portion of a byte array, blocking if necessary.
- write(int)
- Write a byte, blocking if necessary.
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
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
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
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
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.
setError
protected void setError()
- Indicate that an error has occurred.
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
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
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
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
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
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
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
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
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
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
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
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'
).
println
public void println(boolean x)
- Print a boolean, and then finish the line.
- See Also:
- print
println
public void println(char x)
- Print a character, and then finish the line.
- See Also:
- print
println
public void println(int x)
- Print an integer, and then finish the line.
- See Also:
- print
println
public void println(long x)
- Print a long, and then finish the line.
- See Also:
- print
println
public void println(float x)
- Print a float, and then finish the line.
- See Also:
- print
println
public void println(double x)
- Print a double, and then finish the line.
- See Also:
- print
println
public void println(char x[])
- Print an array of characters, and then finish the line.
- See Also:
- print
println
public void println(String x)
- Print a String, and then finish the line.
- See Also:
- print
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
Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.