Class PrintWriter
java.lang.Object
java.io.Writer
java.io.PrintWriter
- All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
Prints formatted text to a writer or a stream. It never throws: an I/O error is recorded and reported by
checkError.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPrintWriter(OutputStream out) PrintWriter(OutputStream out, boolean autoFlush) PrintWriter(Writer out) PrintWriter(Writer out, boolean autoFlush) -
Method Summary
Modifier and TypeMethodDescriptionappend(char c) Writesc.append(CharSequence csq) Writescsq, or "null" when it is null.append(CharSequence csq, int start, int end) Writes the characters ofcsqfromstartup toend.booleanprotected voidvoidclose()Closes the delegate and drops it, as the JDK does: a later write or flush is then suppressed and recorded as an error forcheckError, even when the delegate's own close is a no-op (aStringWriter).voidflush()Flush the stream.Writesformatfilled in withargs, asString.formatdoes.voidprint(boolean b) voidprint(char c) voidprint(char[] s) voidprint(double d) voidprint(float f) voidprint(int i) voidprint(long l) voidvoidWritesformatfilled in withargs, asString.formatdoes.voidprintln()voidprintln(boolean b) voidprintln(char c) voidprintln(char[] s) voidprintln(double d) voidprintln(float f) voidprintln(int i) voidprintln(long l) voidvoidprotected voidsetError()voidwrite(char[] buf) Write an array of characters.voidwrite(char[] buf, int off, int len) Write a portion of an array of characters.voidwrite(int c) Write a single character.voidWrite a string.voidWrite a portion of a string.
-
Field Details
-
out
-
-
Constructor Details
-
PrintWriter
-
PrintWriter
-
PrintWriter
-
PrintWriter
-
-
Method Details
-
checkError
public boolean checkError() -
setError
protected void setError() -
clearError
protected void clearError() -
flush
public void flush()Description copied from class:WriterFlush 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. -
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 forcheckError, even when the delegate's own close is a no-op (aStringWriter). A second close does nothing. -
write
public void write(int c) Description copied from class:WriterWrite 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
-
write
-
write
-
write
-
print
-
print
-
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
-
println
-
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
Description copied from class:WriterWritescsq, or "null" when it is null.- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter
-
append
Description copied from class:WriterWritesc.- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter
-
printf
Writes
formatfilled in withargs, asString.formatdoes.Returns
this writer
-
format
Writes
formatfilled in withargs, asString.formatdoes.Returns
this writer
-
append
Description copied from class:WriterWrites the characters ofcsqfromstartup toend.- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter
-