Team LiB
Previous Section Next Section

PrintStreamjava.io

Java 1.0appendable closeable flushable

This class is a byte output stream that implements a number of methods for displaying textual representations of Java primitive data types. System.out and System.err are PrintStream objects. PrintStream converts characters to bytes using the platform's default charset, or the charset or encoding named in the PrintStream( ) constructor invocation. In Java 5.0, convenience constructors allow you to specify a file (either as a file name or a File object) as the destination of a PrintStream. Prior to Java 5.0 the destination had to be another OutputStream object.

The print( ) methods output standard textual representations of each data type. The println( ) methods do the same and follow the representations with newlines. Each method converts a Java primitive type to a String representation and outputs the resulting string. When an Object is passed to a print( ) or println( ), it is converted to a String by calling its toString( ) method. In Java 5.0, you can also use the printf( ) methods (or the format( ) methods that behave identically) for formatted output. These methods behave like the format( ) method of a java.util.Formatter object that uses the PrintStream as its destination.

This class implements the java.lang.Appendable interface in Java 5.0, which makes it suitable for use with a java.util.Formatter.

See also PrintWriter for a character output stream with similar functionality. And see DataOutputStream for a byte output stream that outputs binary, rather than textual, representations of Java's primitive types.

Figure 9-49. java.io.PrintStream


public class PrintStream extends FilterOutputStream implements Appendable, Closeable {
// Public Constructors
5.0  public PrintStream(File file) throws FileNotFoundException;  
5.0  public PrintStream(String fileName) throws FileNotFoundException;  
     public PrintStream(OutputStream out);  
5.0  public PrintStream(String fileName, String csn) throws FileNotFoundException, 
     UnsupportedEncodingException;  
     public PrintStream(OutputStream out, boolean autoFlush);  
5.0  public PrintStream(File file, String csn) throws FileNotFoundException, 
     UnsupportedEncodingException;  
1.4  public PrintStream(OutputStream out, boolean autoFlush, String encoding) throws 
     UnsupportedEncodingException;  
// Public Instance Methods
5.0  public PrintStream append(char c);  
5.0  public PrintStream append(CharSequence csq);  
5.0  public PrintStream append(CharSequence csq, int start, int end);  
     public boolean checkError( );  
     public void close( );                             Implements:Closeable
5.0  public PrintStream format(String format, Object... args);  
5.0  public PrintStream format(java.util.Locale l, String format, Object... args);  
     public void print(double d);  
     public void print(float f);  
     public void print(char[ ] s);  
     public void print(Object obj);  
     public void print(String s);  
     public void print(long l);  
     public void print(boolean b);  
     public void print(char c);  
     public void print(int i);  
5.0  public PrintStream printf(String format, Object... args);  
5.0  public PrintStream printf(java.util.Locale l, String format, Object... args);  
     public void println( );  
     public void println(char[ ] x);  
     public void println(double x);  
     public void println(Object x);  
     public void println(String x);  
     public void println(float x);  
     public void println(char x);  
     public void println(boolean x);  
     public void println(long x);  
     public void println(int x);  
// Methods Implementing Closeable
     public void close( );  
// Public Methods Overriding FilterOutputStream
     public void flush( );  
     public void write(int b);  
     public void write(byte[ ] buf, int off, int len);  
// Protected Instance Methods
1.1  protected void setError( );  
}

Passed To

System.{setErr( ), setOut( )}, THRowable.printStackTrace( ), java.util.Formatter.Formatter( ), java.util.Properties.list( ), javax.xml.transform.TransformerException.printStackTrace( ), javax.xml.xpath.XPathException.printStackTrace( )

Type Of

System.{err, out}

    Team LiB
    Previous Section Next Section