Top Description Fields Constructors Methods
java.io

public Class PrintStream

extends FilterOutputStream
implements Appendable, Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable, java.lang.Appendable
Known Direct Subclasses
sun.net.smtp.SmtpPrintStream
Imports
java.util.Formatter, .Locale, java.nio.charset.Charset, .IllegalCharsetNameException, .UnsupportedCharsetException, jdk.internal.access.JavaIOPrintStreamAccess, .SharedSecrets, jdk.internal.misc.InternalLock

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 of the underlying output stream 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 default charset if not specified. The PrintWriter class 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 java.nio.charset.CharsetEncoder class should be used when more control over the encoding process is required.

Authors
Frank Yellin, Mark Reinhold
Since
1.0
See Also
Charset#defaultCharset()

Field Summary

Modifier and TypeField and Description
private final boolean
private OutputStreamWriter
private final Charset
private boolean
private Formatter
private final InternalLock
private BufferedWriter
textOut

Track both the text- and character-output streams, so that their buffers can be flushed without flushing the entire stream.

private boolean
Inherited from java.io.FilterOutputStream:
out

Constructor Summary

AccessConstructor and Description
private
PrintStream(boolean autoFlush, OutputStream out)

private
PrintStream(boolean autoFlush, Charset charset, OutputStream out)

public
PrintStream(OutputStream
The output stream to which values and objects will be printed
out
)

Creates a new print stream, without automatic line flushing, with the specified OutputStream.

public
PrintStream(OutputStream
The output stream to which values and objects will be printed
out
,
boolean
Whether the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written
autoFlush
)

Creates a new print stream, with the specified OutputStream and line flushing.

public
PrintStream(OutputStream
The output stream to which values and objects will be printed
out
,
boolean
Whether the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written
autoFlush
,
String
The name of a supported character encoding
encoding
)

Creates a new print stream, with the specified OutputStream, line flushing, and character encoding.

public
PrintStream(OutputStream
The output stream to which values and objects will be printed
out
,
boolean
Whether the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written
autoFlush
,
Charset charset)

Creates a new print stream, with the specified OutputStream, line flushing and charset.

public
PrintStream(String
The name of the file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
fileName
)

Creates a new print stream, without automatic line flushing, with the specified file name.

public
PrintStream(String
The name of the file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
fileName
,
String
The name of a supported charset
csn
)

Creates a new print stream, without automatic line flushing, with the specified file name and charset.

public
PrintStream(String
The name of the file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
fileName
,
Charset charset)

Creates a new print stream, without automatic line flushing, with the specified file name and charset.

public
PrintStream(File
The file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
file
)

Creates a new print stream, without automatic line flushing, with the specified file.

public
PrintStream(File
The file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
file
,
String
The name of a supported charset
csn
)

Creates a new print stream, without automatic line flushing, with the specified file and charset.

public
PrintStream(File
The file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.
file
,
Charset charset)

Creates a new print stream, without automatic line flushing, with the specified file and charset.

Method Summary

Modifier and TypeMethod and Description
public PrintStream

Returns:

This output stream
append
(CharSequence
The character sequence to append. If csq is null, then the four characters "null" are appended to this output stream.
csq
)

Implements java.lang.Appendable.append.

Appends the specified character sequence to this output stream.

public PrintStream

Returns:

This output stream
append
(CharSequence
The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".
csq
,
int
The index of the first character in the subsequence
start
,
int
The index of the character following the last character in the subsequence
end
)

Implements java.lang.Appendable.append.

Appends a subsequence of the specified character sequence to this output stream.

public PrintStream

Returns:

This output stream
append
(char
The 16-bit character to append
c
)

Implements java.lang.Appendable.append.

Appends the specified character to this output stream.

public Charset

Returns:

the charset used in this PrintStream instance
charset
()

Returns the charset used in this PrintStream instance.

public boolean

Returns:

true if and only if this stream has encountered an IOException, or the setError method has been invoked
checkError
()

Flushes the stream if it's not closed and checks its error state.

protected void
clearError()

Clears the error state of this stream.

public void
close()

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Closes the stream.

private void
ensureOpen()

Check to make sure that the stream has not been closed

public void
flush()

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Flushes the stream.

public PrintStream

Returns:

This output stream
format
(String
A format string as described in Format string syntax
format
,
Object...
Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
args
)

Writes a formatted string to this output stream using the specified format string and arguments.

public PrintStream

Returns:

This output stream
format
(Locale
The locale to apply during formatting. If l is null then no localization is applied.
l
,
String
A format string as described in Format string syntax
format
,
Object...
Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
args
)

Writes a formatted string to this output stream using the specified format string and arguments.

private void
private void
private void
implFormat(String format, Object... args)

private void
implFormat(Locale l, String format, Object... args)

private void
private void
implWrite(int b)

private void
implWrite(byte[] buf, int off, int len)

private void
implWrite(char[] buf)

private void
private void
implWriteln(char[] buf)

private void
private void
public PrintStream

Returns:

This output stream
printf
(String
A format string as described in Format string syntax
format
,
Object...
Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
args
)

A convenience method to write a formatted string to this output stream using the specified format string and arguments.

public PrintStream

Returns:

This output stream
printf
(Locale
The locale to apply during formatting. If l is null then no localization is applied.
l
,
String
A format string as described in Format string syntax
format
,
Object...
Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
args
)

A convenience method to write a formatted string to this output stream using the specified format string and arguments.

public void
println()

Terminates the current line by writing the line separator string.

public void
println(boolean
The boolean to be printed
x
)

Prints a boolean and then terminates the line.

public void
println(char
The char to be printed.
x
)

Prints a character and then terminates the line.

public void
println(int
The int to be printed.
x
)

Prints an integer and then terminates the line.

public void
println(long
a The long to be printed.
x
)

Prints a long and then terminates the line.

public void
println(float
The float to be printed.
x
)

Prints a float and then terminates the line.

public void
println(double
The double to be printed.
x
)

Prints a double and then terminates the line.

public void
println(char[]
an array of chars to print.
x
)

Prints an array of characters and then terminates the line.

public void
println(String
The String to be printed.
x
)

Prints a String and then terminates the line.

public void
println(Object
The Object to be printed.
x
)

Prints an Object and then terminates the line.

private static <T> T
requireNonNull(T obj, String message)

requireNonNull is explicitly declared here so as not to create an extra dependency on java.util.Objects.requireNonNull.

protected void
setError()

Sets the error state of the stream to true.

private static Charset
toCharset(String csn)

Returns a charset object for the given charset name.

public void
write(int
The byte to be written
b
)

Overrides java.io.FilterOutputStream.write.

Writes the specified byte to this stream.

public void
write(byte[]
A byte array
buf
,
int
Offset from which to start taking bytes
off
,
int
Number of bytes to write
len
)

Overrides java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this stream.

public void
write(byte[]
A byte array
buf
)

Overrides java.io.FilterOutputStream.write.

Writes all bytes from the specified byte array to this stream.

private void
write(char[] buf)

private void
public void
writeBytes(byte[]
A byte array
buf
)

Writes all bytes from the specified byte array to this stream.

private void
writeln(char[] buf)

private void

Field Detail

autoFlushback to summary
private final boolean autoFlush
charOutback to summary
private OutputStreamWriter charOut
charsetback to summary
private final Charset charset
closingback to summary
private boolean closing
formatterback to summary
private Formatter formatter
lockback to summary
private final InternalLock lock
textOutback to summary
private BufferedWriter textOut

Track both the text- and character-output streams, so that their buffers can be flushed without flushing the entire stream.

troubleback to summary
private boolean trouble

Constructor Detail

PrintStreamback to summary
private PrintStream(boolean autoFlush, OutputStream out)
PrintStreamback to summary
private PrintStream(boolean autoFlush, Charset charset, OutputStream out)
PrintStreamback to summary
public PrintStream(OutputStream out)

Creates a new print stream, without automatic line flushing, with the specified OutputStream. Characters written to the stream are converted to bytes using the default charset, or where out is a PrintStream, the charset used by the print stream.

Parameters
out:OutputStream

The output stream to which values and objects will be printed

See Also
java.io.PrintWriter#PrintWriter(java.io.OutputStream), Charset#defaultCharset()
PrintStreamback to summary
public PrintStream(OutputStream out, boolean autoFlush)

Creates a new print stream, with the specified OutputStream and line flushing. Characters written to the stream are converted to bytes using the default charset, or where out is a PrintStream, the charset used by the print stream.

Parameters
out:OutputStream

The output stream to which values and objects will be printed

autoFlush:boolean

Whether the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written

See Also
java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean), Charset#defaultCharset()
PrintStreamback to summary
public PrintStream(OutputStream out, boolean autoFlush, String encoding) throws UnsupportedEncodingException

Creates a new print stream, with the specified OutputStream, line flushing, and character encoding.

Parameters
out:OutputStream

The output stream to which values and objects will be printed

autoFlush:boolean

Whether the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written

encoding:String

The name of a supported character encoding

Exceptions
UnsupportedEncodingException:
If the named encoding is not supported
Since
1.4
PrintStreamback to summary
public PrintStream(OutputStream out, boolean autoFlush, Charset charset)

Creates a new print stream, with the specified OutputStream, line flushing and charset. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the provided charset.

Parameters
out:OutputStream

The output stream to which values and objects will be printed

autoFlush:boolean

Whether the output buffer will be flushed whenever a byte array is written, one of the println methods is invoked, or a newline character or byte ('\n') is written

charset:Charset

A charset

Since
10
PrintStreamback to summary
public PrintStream(String fileName) throws FileNotFoundException

Creates a new print stream, without automatic line flushing, with the specified file name. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the default charset for this instance of the Java virtual machine.

Parameters
fileName:String

The name of the file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.

Exceptions
FileNotFoundException:
If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
SecurityException:
If a security manager is present and checkWrite(fileName) denies write access to the file
Since
1.5
See Also
Charset#defaultCharset()
PrintStreamback to summary
public PrintStream(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException

Creates a new print stream, without automatic line flushing, with the specified file name and charset. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the provided charset.

Parameters
fileName:String

The name of the file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.

csn:String

The name of a supported charset

Exceptions
FileNotFoundException:
If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
UnsupportedEncodingException:
If the named charset is not supported
SecurityException:
If a security manager is present and checkWrite(fileName) denies write access to the file
Since
1.5
PrintStreamback to summary
public PrintStream(String fileName, Charset charset) throws IOException

Creates a new print stream, without automatic line flushing, with the specified file name and charset. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the provided charset.

Parameters
fileName:String

The name of the file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.

charset:Charset

A charset

Exceptions
IOException:
if an I/O error occurs while opening or creating the file
SecurityException:
If a security manager is present and checkWrite(fileName) denies write access to the file
Since
10
PrintStreamback to summary
public PrintStream(File file) throws FileNotFoundException

Creates a new print stream, without automatic line flushing, with the specified file. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the default charset for this instance of the Java virtual machine.

Parameters
file:File

The file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.

Exceptions
FileNotFoundException:
If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
SecurityException:
If a security manager is present and checkWrite(file.getPath()) denies write access to the file
Since
1.5
See Also
Charset#defaultCharset()
PrintStreamback to summary
public PrintStream(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException

Creates a new print stream, without automatic line flushing, with the specified file and charset. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the provided charset.

Parameters
file:File

The file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.

csn:String

The name of a supported charset

Exceptions
FileNotFoundException:
If the given file object does not denote an existing, writable regular file and a new regular file of that name cannot be created, or if some other error occurs while opening or creating the file
UnsupportedEncodingException:
If the named charset is not supported
SecurityException:
If a security manager is present and checkWrite(file.getPath()) denies write access to the file
Since
1.5
PrintStreamback to summary
public PrintStream(File file, Charset charset) throws IOException

Creates a new print stream, without automatic line flushing, with the specified file and charset. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will encode characters using the provided charset.

Parameters
file:File

The file to use as the destination of this print stream. If the file exists, then it will be truncated to zero size; otherwise, a new file will be created. The output will be written to the file and is buffered.

charset:Charset

A charset

Exceptions
IOException:
if an I/O error occurs while opening or creating the file
SecurityException:
If a security manager is present and checkWrite(file.getPath()) denies write access to the file
Since
10

Method Detail

appendback to summary
public PrintStream append(CharSequence csq)

Implements java.lang.Appendable.append.

Appends the specified character sequence to this output stream.

An invocation of this method of the form out.append(csq) behaves in exactly the same way as the invocation

out.print(csq.toString())
out.print(csq.toString())

Depending on the specification of toString for the character sequence csq, the entire sequence may not be appended. For instance, invoking then toString method of a character buffer will return a subsequence whose content depends upon the buffer's position and limit.

Parameters
csq:CharSequence

The character sequence to append. If csq is null, then the four characters "null" are appended to this output stream.

Returns:PrintStream

This output stream

Since
1.5
appendback to summary
public PrintStream append(CharSequence csq, int start, int end)

Implements java.lang.Appendable.append.

Appends a subsequence of the specified character sequence to this output stream.

An invocation of this method of the form out.append(csq, start, end) when csq is not null, behaves in exactly the same way as the invocation

out.print(csq.subSequence(start, end).toString())
out.print(csq.subSequence(start, end).toString())
Parameters
csq:CharSequence

The character sequence from which a subsequence will be appended. If csq is null, then characters will be appended as if csq contained the four characters "null".

start:int

The index of the first character in the subsequence

end:int

The index of the character following the last character in the subsequence

Returns:PrintStream

This output stream

Exceptions
IndexOutOfBoundsException:
If start or end are negative, start is greater than end, or end is greater than csq.length()
Since
1.5
appendback to summary
public PrintStream append(char c)

Implements java.lang.Appendable.append.

Appends the specified character to this output stream.

An invocation of this method of the form out.append(c) behaves in exactly the same way as the invocation

out.print(c)
out.print(c)
Parameters
c:char

The 16-bit character to append

Returns:PrintStream

This output stream

Since
1.5
charsetback to summary
public Charset charset()

Returns the charset used in this PrintStream instance.

Returns:Charset

the charset used in this PrintStream instance

Since
18
checkErrorback to summary
public boolean checkError()

Flushes the stream if it's not closed and checks its error state.

Returns:boolean

true if and only if this stream has encountered an IOException, or the setError method has been invoked

clearErrorback to summary
protected void clearError()

Clears the error state of this stream.

This method will cause subsequent invocations of checkError() to return false until another write operation fails and invokes setError().

Since
1.6
closeback to summary
public void close()

Overrides java.io.FilterOutputStream.close.

Implements java.io.Closeable.close.

Closes the stream. This is done by flushing the stream and then closing the underlying output stream.

Annotations
@Override
See Also
java.io.OutputStream#close()
ensureOpenback to summary
private void ensureOpen() throws IOException

Check to make sure that the stream has not been closed

flushback to summary
public void flush()

Overrides java.io.FilterOutputStream.flush.

Implements java.io.Flushable.flush.

Flushes the stream. This is done by writing any buffered output bytes to the underlying output stream and then flushing that stream.

Annotations
@Override
See Also
java.io.OutputStream#flush()
formatback to summary
public PrintStream format(String format, Object... args)

Writes a formatted string to this output stream using the specified format string and arguments.

The locale always used is the one returned by java.util.Locale#getDefault(Locale.Category) with FORMAT category specified, regardless of any previous invocations of other formatting methods on this object.

Parameters
format:String

A format string as described in Format string syntax

args:Object[]

Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.

Returns:PrintStream

This output stream

Exceptions
IllegalFormatException:
If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
NullPointerException:
If the format is null
Since
1.5
formatback to summary
public PrintStream format(Locale l, String format, Object... args)

Writes a formatted string to this output stream using the specified format string and arguments.

Parameters
l:Locale

The locale to apply during formatting. If l is null then no localization is applied.

format:String

A format string as described in Format string syntax

args:Object[]

Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.

Returns:PrintStream

This output stream

Exceptions
IllegalFormatException:
If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
NullPointerException:
If the format is null
Since
1.5
implCloseback to summary
private void implClose()
implFlushback to summary
private void implFlush()
implFormatback to summary
private void implFormat(String format, Object... args) throws IOException
implFormatback to summary
private void implFormat(Locale l, String format, Object... args) throws IOException
implNewLineback to summary
private void implNewLine() throws IOException
implWriteback to summary
private void implWrite(int b) throws IOException
implWriteback to summary
private void implWrite(byte[] buf, int off, int len) throws IOException
implWriteback to summary
private void implWrite(char[] buf) throws IOException
implWriteback to summary
private void implWrite(String s) throws IOException
implWritelnback to summary
private void implWriteln(char[] buf) throws IOException
implWritelnback to summary
private void implWriteln(String s) throws IOException
newLineback to summary
private void newLine()
printfback to summary
public PrintStream printf(String format, Object... args)

A convenience method to write a formatted string to this output stream using the specified format string and arguments.

An invocation of this method of the form out.printf(format, args) behaves in exactly the same way as the invocation

out.format(format, args)
out.format(format, args)
Parameters
format:String

A format string as described in Format string syntax

args:Object[]

Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.

Returns:PrintStream

This output stream

Exceptions
IllegalFormatException:
If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
NullPointerException:
If the format is null
Since
1.5
printfback to summary
public PrintStream printf(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.

An invocation of this method of the form out.printf(l, format, args) behaves in exactly the same way as the invocation

out.format(l, format, args)
out.format(l, format, args)
Parameters
l:Locale

The locale to apply during formatting. If l is null then no localization is applied.

format:String

A format string as described in Format string syntax

args:Object[]

Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.

Returns:PrintStream

This output stream

Exceptions
IllegalFormatException:
If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
NullPointerException:
If the format is null
Since
1.5
printlnback to summary
public void println()

Terminates the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').

printlnback to summary
public void println(boolean x)

Prints a boolean and then terminates the line. This method behaves as though it invokes print(boolean) and then println().

Parameters
x:boolean

The boolean to be printed

printlnback to summary
public void println(char x)

Prints a character and then terminates the line. This method behaves as though it invokes print(char) and then println().

Parameters
x:char

The char to be printed.

printlnback to summary
public void println(int x)

Prints an integer and then terminates the line. This method behaves as though it invokes print(int) and then println().

Parameters
x:int

The int to be printed.

printlnback to summary
public void println(long x)

Prints a long and then terminates the line. This method behaves as though it invokes print(long) and then println().

Parameters
x:long

a The long to be printed.

printlnback to summary
public void println(float x)

Prints a float and then terminates the line. This method behaves as though it invokes print(float) and then println().

Parameters
x:float

The float to be printed.

printlnback to summary
public void println(double x)

Prints a double and then terminates the line. This method behaves as though it invokes print(double) and then println().

Parameters
x:double

The double to be printed.

printlnback to summary
public void println(char[] x)

Prints an array of characters and then terminates the line. This method behaves as though it invokes print(char[]) and then println().

Parameters
x:char[]

an array of chars to print.

printlnback to summary
public void println(String x)

Prints a String and then terminates the line. This method behaves as though it invokes print(String) and then println().

Parameters
x:String

The String to be printed.

printlnback to summary
public void println(Object x)

Prints an Object and then terminates the line. This method calls at first String.valueOf(x) to get the printed object's string value, then behaves as though it invokes print(String) and then println().

Parameters
x:Object

The Object to be printed.

requireNonNullback to summary
private static <T> T requireNonNull(T obj, String message)

requireNonNull is explicitly declared here so as not to create an extra dependency on java.util.Objects.requireNonNull. PrintStream is loaded early during system initialization.

setErrorback to summary
protected void setError()

Sets the error state of the stream to true.

This method will cause subsequent invocations of checkError() to return true until clearError() is invoked.

Since
1.1
toCharsetback to summary
private static Charset toCharset(String csn) throws UnsupportedEncodingException

Returns a charset object for the given charset name.

Exceptions
UnsupportedEncodingException:
if the charset is not supported
NullPointerException:
is csn is null
writeback to summary
public void write(int b)

Overrides java.io.FilterOutputStream.write.

Writes the specified byte to this stream. If the byte is a newline and automatic flushing is enabled then the flush method will be invoked on the underlying output stream.

Note that the byte is written as given; to write a character that will be translated according to the default charset, use the print(char) or println(char) methods.

Parameters
b:int

The byte to be written

Annotations
@Override
See Also
print(char), println(char)
writeback to summary
public void write(byte[] buf, int off, int len)

Overrides java.io.FilterOutputStream.write.

Writes len bytes from the specified byte array starting at offset off to this stream. If automatic flushing is enabled then the flush method will be invoked on the underlying output stream.

Note that the bytes will be written as given; to write characters that will be translated according to the default charset, use the print(char) or println(char) methods.

Parameters
buf:byte[]

A byte array

off:int

Offset from which to start taking bytes

len:int

Number of bytes to write

Annotations
@Override
Exceptions
IndexOutOfBoundsException:
If off is negative, len is negative, or len is greater than b.length - off
writeback to summary
public void write(byte[] buf) throws IOException

Overrides java.io.FilterOutputStream.write.

Writes all bytes from the specified byte array to this stream. If automatic flushing is enabled then the flush method will be invoked on the underlying output stream.

Note that the bytes will be written as given; to write characters that will be translated according to the default charset, use the print(char[]) or println(char[]) methods.

API Note

Although declared to throw IOException, this method never actually does so. Instead, like other methods that this class overrides, it sets an internal flag which may be tested via the checkError() method. To write an array of bytes without having to write a catch block for the IOException, use either writeBytes(buf) or write(buf, 0, buf.length).

Implementation Specification

This method is equivalent to this.write(buf, 0, buf.length).

Parameters
buf:byte[]

A byte array

Annotations
@Override
Exceptions
IOException:
If an I/O error occurs.
Since
14
See Also
writeBytes(byte[]), write(byte[], int, int)
writeback to summary
private void write(char[] buf)
writeback to summary
private void write(String s)
writeBytesback to summary
public void writeBytes(byte[] buf)

Writes all bytes from the specified byte array to this stream. If automatic flushing is enabled then the flush method will be invoked.

Note that the bytes will be written as given; to write characters that will be translated according to the default charset, use the print(char[]) or println(char[]) methods.

Implementation Specification

This method is equivalent to this.write(buf, 0, buf.length).

Parameters
buf:byte[]

A byte array

Since
14
writelnback to summary
private void writeln(char[] buf)
writelnback to summary
private void writeln(String s)