Package java.io |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
public class java.io.PrintStream extends java.io.FilterOutputStream { // Constructors public PrintStream(OutputStream out); public PrintStream(OutputStream out, boolean autoflush); // Methods public boolean checkError(); public void close(); public void flush(); public void print(boolean b); public void print(char c); public void print(char s[]); public void print(double d); public void print(float f); public void print(int i); public void print(long l); public void print(Object obj); public void print(String s); public void println(); public void println(boolean b); public void println(char c); public void println(char s[]); public void println(double d); public void println(float f); public void println(int i); public void println(long l); public void println(Object obj); public void println(String s); public void write(byte b[], int off, int len); public void write(int b); }
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 .
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:
System.out.println("Hello world!"); System.out.print("x = "); System.out.println(x); System.out.println("y = " + y);
public PrintStream(OutputStream out)Constructs a new print stream that writes its output to the specified underlying output stream .
Parameter Description out the underlying output stream
public PrintStream(OutputStream out, boolean autoflush)Constructs a new print stream that writes its output to the specified underlying output stream . 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.
Parameter Description out the underlying output stream autoflush if true the stream automatically flushes its output when a newline character is printed
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.
Return Value:
Returns true if the print stream has ever encountered an error on the output stream; false otherwise.
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 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 (see checkError).
Overrides:
close in class FilterOutputStream .
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 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 (see checkError).
Overrides:
flush in class FilterOutputStream .
public void print(boolean b)Prints the string "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.
Parameter Description b a boolean to be printed
public void print(char c)Prints the low eight bits of the character argument to this print stream's underlying output stream .
Parameter Description c a char to be printed
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 .
Parameter Description s an array of chars to be printed
public void print(double d)Prints the string representation of the 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.
Parameter Description d a double to be printed
public void print(float f)Prints the string representation of the 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.
Parameter Description f a float to be printed
public void print(int i)Prints the string representation of the 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.
Parameter Description i an int to be printed
public void print(long l)Prints the string representation of the 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.
Parameter Description l a long to be printed.
public void print(Object obj)Prints the string representation of the 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 .
Parameter Description obj an Object to be printed
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 .
Parameter Description s a String to be printed
public void println()Prints a newline character to this print stream's underlying output stream .
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 .
Parameter Description b a boolean to be printed
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 .
Parameter Description c a char to be printed
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 .
Parameter Description s an array of characters to be printed
public void println(double d)Prints the string representation of the 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.
Parameter Description d a double to be printed
public void println(float f)Prints the string representation of the 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.
Parameter Description f a float to be printed
public void println(int i)Prints the string representation of the 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.
Parameter Description i an int to be printed
public void println(long l)Prints the string representation of the 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.
Parameter Description l a long to be printed
public void println(Object obj)Prints the string representation of the 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 .
Parameter Description obj an Object to be printed
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 .
Parameter Description s a String to be printed
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 .
Parameter Description b the data off the start offset in the data len the number of bytes to write Overrides:
write in class FilterOutputStream .
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 . 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
Parameter Description b the byte Overrides:
write in class FilterOutputStream .