PrintStream class methods in Java

java.io.PrintStream

A PrintStream adds 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, a PrintStream never throws an IOException; instead, exceptional situations merely set an internal flag that can be tested via the checkError method.

Optionally, a PrintStream can be created so as to flush automatically; this means that the flush method is automatically invoked after a byte array is written, one of the println methods is invoked, or a newline character or byte('\n') is written.

All characters printed by a PrintStream are converted into bytes using the given encoding or charset, or the platform's default character encoding if not specified. The PrintWriter class should be used in situations that require writing characters rather than bytes.

Implemented Interfaces:

Closeable

Flushable

Appendable

AutoCloseable

Subclasses:

LogStream

Some methods of PrintStream class.

append(char)This method appends the specified character to this output stream.

append(CharSequence)This method appends the specified character sequence to this output stream.

append(CharSequence, int, int)This method appends a subsequence of the specified character sequence to this output stream.

checkError()This method flushes the stream and checks its error state.

close()This is done by flushing the stream and then closing the underlying output stream.

flush()This method flushes the stream.

format(String, Object...)This method writes a formatted string to this output stream using the specified format string and arguments.

format(Locale, String, Object...)This method writes a formatted string to this output stream using the specified format string and arguments.

print(boolean)This method prints a boolean value.

printf(String, Object...)It is a convenient method to write a formatted string to this output stream using the specified format string and arguments.

printf(Locale, String, Object...)It is a convenient method to write a formatted string to this output stream using the specified format string and arguments.

println()This method terminates the current line by writing the line separator string.

PrintStream(File)This method creates a new print stream, without automatic line flushing, with the specified file.

PrintStream(OutputStream, boolean, String)This method creates a new print stream, with the specified OutputStream, line flushing, and character encoding.

PrintStream(OutputStream)This method creates a new print stream, without automatic line flushing, with the specified OutputStream.

PrintStream(String)This method creates a new print stream, without automatic line flushing, with the specified file name.

PrintStream(File, Charset)This method creates a new print stream, without automatic line flushing, with the specified file and charset.

PrintStream(File, String)This method creates a new print stream, without automatic line flushing, with the specified file and charset.

PrintStream(OutputStream, boolean)This method creates a new print stream, with the specified OutputStream and line flushing.

PrintStream(String, Charset)This method creates a new print stream, without automatic line flushing, with the specified file name and charset.

PrintStream(String, String)This method creates a new print stream, without automatic line flushing, with the specified file name and charset.

PrintStream(OutputStream, boolean, Charset)This method creates a new print stream, with the specified OutputStream, line flushing, and charset.

write(byte[]) This method writes all bytes from the specified byte array to this stream.

write(int)This method writes the specified byte to this stream.

write(byte[], int, int)This method writes len bytes from the specified byte array starting to offset off to this stream.

writeBytes(byte[])This method writes all bytes from the specified byte array to this stream.

No comments:

Post a Comment