Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public class PrintWriter

  1. Object
  2. Writer
  3. PrintWriter

ImplementsAppendable, AutoCloseable, Closeable, Flushable

Prints formatted text to a writer or a stream. It never throws: an I/O error is recorded and reported by checkError.

Fields

protected Writer out

Constructors

public PrintWriter(Writer out)
public PrintWriter(Writer out, boolean autoFlush)
public PrintWriter(OutputStream out)
public PrintWriter(OutputStream out, boolean autoFlush)

Methods

public boolean checkError()
protected void setError()
protected void clearError()
public void flush()Flush the stream.
public void close()Closes the delegate and drops it, as the JDK does: a later write or flush is then suppressed and recorded as an error for checkError, even when the delegate’s own close is a no-op (a StringWriter).
public void write(int c)Write a single character.
public void write(char[] buf, int off, int len)Write a portion of an array of characters.
public void write(char[] buf)Write an array of characters.
public void write(String s, int off, int len)Write a portion of a string.
public void write(String s)Write a string.
public void print(String s)
public void print(Object o)
public void print(char c)
public void print(char[] s)
public void print(boolean b)
public void print(int i)
public void print(long l)
public void print(float f)
public void print(double d)
public void println()
public void println(String s)
public void println(Object o)
public void println(char c)
public void println(char[] s)
public void println(boolean b)
public void println(int i)
public void println(long l)
public void println(float f)
public void println(double d)
public PrintWriter append(CharSequence csq)Writes csq, or “null” when it is null.
public PrintWriter append(char c)Writes c.
public PrintWriter printf(String format, Object... args)Writes format filled in with args, as String.format does.
public PrintWriter format(String format, Object... args)Writes format filled in with args, as String.format does.
public PrintWriter append(CharSequence csq, int start, int end)Writes the characters of csq from start up to end.

Inherited fields

Inherited methods

Field details

out

protected Writer out

Constructor details

PrintWriter

public PrintWriter(Writer out)

PrintWriter

public PrintWriter(Writer out, boolean autoFlush)

PrintWriter

public PrintWriter(OutputStream out)

PrintWriter

public PrintWriter(OutputStream out, boolean autoFlush)

Method details

checkError

public boolean checkError()

setError

protected void setError()

clearError

protected void clearError()

flush

public void flush()
Flush the stream. If the stream has saved any characters from the various write() methods in a buffer, write them immediately to their intended destination. Then, if that destination is another character or byte stream, flush it. Thus one flush() invocation will flush all the buffers in a chain of Writers and OutputStreams.

Throws

IOException
if there are any issues writing the data.

close

public void close()
Closes the delegate and drops it, as the JDK does: a later write or flush is then suppressed and recorded as an error for checkError, even when the delegate’s own close is a no-op (a StringWriter). A second close does nothing.

write

public void write(int c)
Write a single character. The character to be written is contained in the 16 low-order bits of the given integer value; the 16 high-order bits are ignored. Subclasses that intend to support efficient single-character output should override this method.

write

public void write(char[] buf, int off, int len)
Write a portion of an array of characters.

write

public void write(char[] buf)
Write an array of characters.

write

public void write(String s, int off, int len)
Write a portion of a string.

write

public void write(String s)
Write a string.

print

public void print(String s)

print

public void print(Object o)

print

public void print(char c)

print

public void print(char[] s)

print

public void print(boolean b)

print

public void print(int i)

print

public void print(long l)

print

public void print(float f)

print

public void print(double d)

println

public void println()

println

public void println(String s)

println

public void println(Object o)

println

public void println(char c)

println

public void println(char[] s)

println

public void println(boolean b)

println

public void println(int i)

println

public void println(long l)

println

public void println(float f)

println

public void println(double d)

append

public PrintWriter append(CharSequence csq)
Writes csq, or “null” when it is null.

Parameters

csq CharSequence
the character sequence to append.

Returns

this Appendable.

Throws

IOException
if an I/O error occurs.

append

public PrintWriter append(char c)
Writes c.

Parameters

c char
the character to append.

Returns

this Appendable.

Throws

IOException
if an I/O error occurs.

printf

public PrintWriter printf(String format, Object... args)
Writes format filled in with args, as String.format does.

Returns

this writer

format

public PrintWriter format(String format, Object... args)
Writes format filled in with args, as String.format does.

Returns

this writer

append

public PrintWriter append(CharSequence csq, int start, int end)
Writes the characters of csq from start up to end.

Parameters

csq CharSequence
the character sequence to append.
start int
the first index of the subsequence of csq that is appended.
end int
the last index of the subsequence of csq that is appended.

Returns

this Appendable.

Throws

IndexOutOfBoundsException
if start end or end is greater than the length of csq.
IOException
if an I/O error occurs.