Class PrintWriter

java.lang.Object
java.io.Writer
java.io.PrintWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class PrintWriter extends Writer
Prints formatted text to a writer or a stream. It never throws: an I/O error is recorded and reported by checkError.
  • Field Details

  • 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()
      Description copied from class: Writer
      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.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
    • 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.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
    • write

      public void write(int c)
      Description copied from class: Writer
      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.
      Overrides:
      write in class Writer
    • write

      public void write(char[] buf, int off, int len)
      Description copied from class: Writer
      Write a portion of an array of characters.
      Specified by:
      write in class Writer
    • write

      public void write(char[] buf)
      Description copied from class: Writer
      Write an array of characters.
      Overrides:
      write in class Writer
    • write

      public void write(String s, int off, int len)
      Description copied from class: Writer
      Write a portion of a string.
      Overrides:
      write in class Writer
    • write

      public void write(String s)
      Description copied from class: Writer
      Write a string.
      Overrides:
      write in class Writer
    • 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)
      Description copied from class: Writer
      Writes csq, or "null" when it is null.
      Specified by:
      append in interface Appendable
      Overrides:
      append in class Writer
    • append

      public PrintWriter append(char c)
      Description copied from class: Writer
      Writes c.
      Specified by:
      append in interface Appendable
      Overrides:
      append in class Writer
    • 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)
      Description copied from class: Writer
      Writes the characters of csq from start up to end.
      Specified by:
      append in interface Appendable
      Overrides:
      append in class Writer