Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Class java.io.PrintStream

java.lang.Object
    |
    +----java.io.OutputStream
            |
            +----java.io.FilterOutputStream
                    |
                    +----java.io.PrintStream
Subclasses:
LogStream

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.

Since:
JDK1.0
See Also:
PrintWriter

Fields inherited from class java.io.FilterOutputStream
 out
 

Constructor Summary
 PrintStream(OutputStream out)
Create a new print stream. Deprecated
 PrintStream(OutputStream out, boolean autoFlush)
Create a new PrintStream. Deprecated
 

Method Summary
boolean  checkError()
Flush the stream and check its error state.
void  close()
Close the stream.
void  flush()
Flush the stream.
void  print(boolean b)
Print a boolean value.
void  print(char c)
Print a character.
void  print(int i)
Print an integer.
void  print(long l)
Print a long integer.
void  print(float f)
Print a floating-point number.
void  print(double d)
Print a double-precision floating-point number.
void  print(char[] s)
Print an array of characters.
void  print(String s)
Print a string.
void  print(Object obj)
Print an object.
void  println()
Finish the current line by writing a line separator.
void  println(boolean x)
Print a boolean, and then finish the line.
void  println(char x)
Print a character, and then finish the line.
void  println(int x)
Print an integer, and then finish the line.
void  println(long x)
Print a long, and then finish the line.
void  println(float x)
Print a float, and then finish the line.
void  println(double x)
Print a double, and then finish the line.
void  println(char[] x)
Print an array of characters, and then finish the line.
void  println(String x)
Print a String, and then finish the line.
void  println(Object x)
Print an Object, and then finish the line.
void  setError()
Indicate that an error has occurred.
void  write(int b)
Write a byte, blocking if necessary.
void  write(byte[] buf, int off, int len)
Write a portion of a byte array, blocking if necessary.
 
Methods inherited from class java.io.FilterOutputStream
 close, flush, write, write, write
 
Methods inherited from class java.io.OutputStream
 close, flush, write, write, write
 
Methods inherited from class java.lang.Object
 clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

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(java.io.OutputStream)

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(java.io.OutputStream, boolean)
Method Detail

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(char), println(char)

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(int)

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(long)

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(float)

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(double)

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(boolean)

println

public void println(char x)
Print a character, and then finish the line.
See Also:
print(char)

println

public void println(int x)
Print an integer, and then finish the line.
See Also:
print(int)

println

public void println(long x)
Print a long, and then finish the line.
See Also:
print(long)

println

public void println(float x)
Print a float, and then finish the line.
See Also:
print(float)

println

public void println(double x)
Print a double, and then finish the line.
See Also:
print(double)

println

public void println(char[] x)
Print an array of characters, and then finish the line.
See Also:
print(char[])

println

public void println(String x)
Print a String, and then finish the line.
See Also:
print(String)

println

public void println(Object x)
Print an Object, and then finish the line.
See Also:
print(Object)

Contents | Package | Class | Tree | Deprecated | Index | Help Java 1.2 Beta 3
PREV | NEXT SHOW LISTS | HIDE LISTS

Submit a bug or feature
Submit comments/suggestions about new javadoc look.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.