- java.lang.Object
-
- java.io.OutputStream
-
- java.io.FilterOutputStream
-
- java.io.PrintStream
-
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
- Direct Known Subclasses:
LogStream
public class PrintStream extends FilterOutputStream implements Appendable, Closeable
APrintStreamadds functionality to another output stream, namely the ability to print representations of various data values conveniently. Two other features are provided as well. Unlike other output streams, aPrintStreamnever throws anIOException; instead, exceptional situations merely set an internal flag that can be tested via thecheckErrormethod. Optionally, aPrintStreamcan be created so as to flush automatically; this means that theflushmethod is automatically invoked after a byte array is written, one of theprintlnmethods is invoked, or a newline character or byte ('\n') is written.All characters printed by a
PrintStreamare converted into bytes using the given encoding or charset, or platform's default character encoding if not specified. ThePrintWriterclass should be used in situations that require writing characters rather than bytes.This class always replaces malformed and unmappable character sequences with the charset's default replacement string. The CharsetEncoder class should be used when more control over the encoding process is required.
- Since:
- 1.0
-
-
Field Summary
-
Fields declared in class java.io.FilterOutputStream
out
-
-
Constructor Summary
Constructors Constructor Description PrintStream(File file)Creates a new print stream, without automatic line flushing, with the specified file.PrintStream(File file, String csn)Creates a new print stream, without automatic line flushing, with the specified file and charset.PrintStream(File file, Charset charset)Creates a new print stream, without automatic line flushing, with the specified file and charset.PrintStream(OutputStream out)Creates a new print stream.PrintStream(OutputStream out, boolean autoFlush)Creates a new print stream.PrintStream(OutputStream out, boolean autoFlush, String encoding)Creates a new print stream.PrintStream(OutputStream out, boolean autoFlush, Charset charset)Creates a new print stream, with the specified OutputStream, automatic line flushing and charset.PrintStream(String fileName)Creates a new print stream, without automatic line flushing, with the specified file name.PrintStream(String fileName, String csn)Creates a new print stream, without automatic line flushing, with the specified file name and charset.PrintStream(String fileName, Charset charset)Creates a new print stream, without automatic line flushing, with the specified file name and charset.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PrintStreamappend(char c)Appends the specified character to this output stream.PrintStreamappend(CharSequence csq)Appends the specified character sequence to this output stream.PrintStreamappend(CharSequence csq, int start, int end)Appends a subsequence of the specified character sequence to this output stream.booleancheckError()Flushes the stream and checks its error state.protected voidclearError()Clears the internal error state of this stream.voidclose()Closes the stream.voidflush()Flushes the stream.PrintStreamformat(String format, Object... args)Writes a formatted string to this output stream using the specified format string and arguments.PrintStreamformat(Locale l, String format, Object... args)Writes a formatted string to this output stream using the specified format string and arguments.voidprint(boolean b)Prints a boolean value.voidprint(char c)Prints a character.voidprint(char[] s)Prints an array of characters.voidprint(double d)Prints a double-precision floating-point number.voidprint(float f)Prints a floating-point number.voidprint(int i)Prints an integer.voidprint(long l)Prints a long integer.voidprint(Object obj)Prints an object.voidprint(String s)Prints a string.PrintStreamprintf(String format, Object... args)A convenience method to write a formatted string to this output stream using the specified format string and arguments.PrintStreamprintf(Locale l, String format, Object... args)A convenience method to write a formatted string to this output stream using the specified format string and arguments.voidprintln()Terminates the current line by writing the line separator string.voidprintln(boolean x)Prints a boolean and then terminate the line.voidprintln(char x)Prints a character and then terminate the line.voidprintln(char[] x)Prints an array of characters and then terminate the line.voidprintln(double x)Prints a double and then terminate the line.voidprintln(float x)Prints a float and then terminate the line.voidprintln(int x)Prints an integer and then terminate the line.voidprintln(long x)Prints a long and then terminate the line.voidprintln(Object x)Prints an Object and then terminate the line.voidprintln(String x)Prints a String and then terminate the line.protected voidsetError()Sets the error state of the stream totrue.voidwrite(byte[] buf, int off, int len)Writeslenbytes from the specified byte array starting at offsetoffto this stream.voidwrite(int b)Writes the specified byte to this stream.-
Methods declared in class java.io.FilterOutputStream
write
-
Methods declared in class java.io.OutputStream
nullOutputStream
-
-