IT. Expert System.

Android Reference

PrintWriter


java.io

Class PrintWriter

  • All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable


    public class PrintWriter
    extends Writer
    Wraps either an existing OutputStream or an existing Writer and provides convenience methods for printing common data types in a human readable format. No IOException is thrown by this class. Instead, callers should use checkError() to see if a problem has occurred in this writer.
    • Field Summary

      Fields
      Modifier and Type Field and Description
      protected Writer out
      The writer to print data to.
    • Constructor Summary

      Constructors
      Constructor and Description
      PrintWriter(File file)
      Constructs a new PrintWriter with file as its target.
      PrintWriter(File file, String csn)
      Constructs a new PrintWriter with file as its target.
      PrintWriter(OutputStream out)
      Constructs a new PrintWriter with out as its target stream.
      PrintWriter(OutputStream out, boolean autoFlush)
      Constructs a new PrintWriter with out as its target stream.
      PrintWriter(String fileName)
      Constructs a new PrintWriter with the file identified by fileName as its target.
      PrintWriter(String fileName, String csn)
      Constructs a new PrintWriter with the file identified by fileName as its target.
      PrintWriter(Writer wr)
      Constructs a new PrintWriter with wr as its target writer.
      PrintWriter(Writer wr, boolean autoFlush)
      Constructs a new PrintWriter with out as its target writer.
    • Method Summary

      Methods
      Modifier and Type Method and Description
      PrintWriter append(char c)
      Appends the character c to the target.
      PrintWriter append(CharSequence csq)
      Appends the character sequence csq to the target.
      PrintWriter append(CharSequence csq, int start, int end)
      Appends a subsequence of the character sequence csq to the target.
      boolean checkError()
      Flushes this writer and returns the value of the error flag.
      protected void clearError()
      Sets the error state of the stream to false.
      void close()
      Closes this print writer.
      void flush()
      Ensures that all pending data is sent out to the target.
      PrintWriter format(Locale l, String format, Object... args)
      Writes a string formatted by an intermediate Formatter to the target using the specified locale, format string and arguments.
      PrintWriter format(String format, Object... args)
      Formats args according to the format string format, and writes the result to this stream.
      void print(boolean bool)
      Prints the string representation of the specified boolean to the target.
      void print(char ch)
      Prints the string representation of the specified character to the target.
      void print(char[] charArray)
      Prints the string representation of the specified character array to the target.
      void print(double dnum)
      Prints the string representation of the specified double to the target.
      void print(float fnum)
      Prints the string representation of the specified float to the target.
      void print(int inum)
      Prints the string representation of the specified integer to the target.
      void print(long lnum)
      Prints the string representation of the specified long to the target.
      void print(Object obj)
      Prints the string representation of the specified object to the target.
      void print(String str)
      Prints a string to the target.
      PrintWriter printf(Locale l, String format, Object... args)
      Prints a formatted string.
      PrintWriter printf(String format, Object... args)
      Prints a formatted string.
      void println()
      Prints a newline.
      void println(boolean b)
      Prints the string representation of the boolean b followed by a newline.
      void println(char c)
      Prints the string representation of the char c followed by a newline.
      void println(char[] chars)
      Prints the string representation of the character array chars followed by a newline.
      void println(double d)
      Prints the string representation of the double d followed by a newline.
      void println(float f)
      Prints the string representation of the float f followed by a newline.
      void println(int i)
      Prints the string representation of the int i followed by a newline.
      void println(long l)
      Prints the string representation of the long l followed by a newline.
      void println(Object obj)
      Prints the string representation of the object o, or "null, followed by a newline.
      void println(String str)
      Prints the string representation of the string s followed by a newline.
      protected void setError()
      Sets the error flag of this writer to true.
      void write(char[] buf)
      Writes the character buffer buf to the target.
      void write(char[] buf, int offset, int count)
      Writes count characters from buffer starting at offset to the target.
      void write(int oneChar)
      Writes one character to the target.
      void write(String str)
      Writes the characters from the specified string to the target.
      void write(String str, int offset, int count)
      Writes count characters from str starting at offset to the target.
    • Field Detail

      • out

        protected Writer out
        The writer to print data to.
    • Constructor Detail

      • PrintWriter

        public PrintWriter(OutputStream out)
        Constructs a new PrintWriter with out as its target stream. By default, the new print writer does not automatically flush its contents to the target stream when a newline is encountered.
        Parameters:
        out - the target output stream.
        Throws:
        NullPointerException - if out is null.
      • PrintWriter

        public PrintWriter(OutputStream out,
                   boolean autoFlush)
        Constructs a new PrintWriter with out as its target stream. The parameter autoFlush determines if the print writer automatically flushes its contents to the target stream when a newline is encountered.
        Parameters:
        out - the target output stream.
        autoFlush - indicates whether contents are flushed upon encountering a newline sequence.
        Throws:
        NullPointerException - if out is null.
      • PrintWriter

        public PrintWriter(Writer wr)
        Constructs a new PrintWriter with wr as its target writer. By default, the new print writer does not automatically flush its contents to the target writer when a newline is encountered.
        Parameters:
        wr - the target writer.
        Throws:
        NullPointerException - if wr is null.
      • PrintWriter

        public PrintWriter(Writer wr,
                   boolean autoFlush)
        Constructs a new PrintWriter with out as its target writer. The parameter autoFlush determines if the print writer automatically flushes its contents to the target writer when a newline is encountered.
        Parameters:
        wr - the target writer.
        autoFlush - indicates whether to flush contents upon encountering a newline sequence.
        Throws:
        NullPointerException - if out is null.
      • PrintWriter

        public PrintWriter(File file)
                    throws FileNotFoundException
        Constructs a new PrintWriter with file as its target. The VM's default character set is used for character encoding. The print writer does not automatically flush its contents to the target file when a newline is encountered. The output to the file is buffered.
        Parameters:
        file - the target file. If the file already exists, its contents are removed, otherwise a new file is created.
        Throws:
        FileNotFoundException - if an error occurs while opening or creating the target file.
      • PrintWriter

        public PrintWriter(File file,
                   String csn)
                    throws FileNotFoundException,
                           UnsupportedEncodingException
        Constructs a new PrintWriter with file as its target. The character set named csn is used for character encoding. The print writer does not automatically flush its contents to the target file when a newline is encountered. The output to the file is buffered.
        Parameters:
        file - the target file. If the file already exists, its contents are removed, otherwise a new file is created.
        csn - the name of the character set used for character encoding.
        Throws:
        FileNotFoundException - if an error occurs while opening or creating the target file.
        NullPointerException - if csn is null.
        UnsupportedEncodingException - if the encoding specified by csn is not supported.
      • PrintWriter

        public PrintWriter(String fileName)
                    throws FileNotFoundException
        Constructs a new PrintWriter with the file identified by fileName as its target. The VM's default character set is used for character encoding. The print writer does not automatically flush its contents to the target file when a newline is encountered. The output to the file is buffered.
        Parameters:
        fileName - the target file's name. If the file already exists, its contents are removed, otherwise a new file is created.
        Throws:
        FileNotFoundException - if an error occurs while opening or creating the target file.
      • PrintWriter

        public PrintWriter(String fileName,
                   String csn)
                    throws FileNotFoundException,
                           UnsupportedEncodingException
        Constructs a new PrintWriter with the file identified by fileName as its target. The character set named csn is used for character encoding. The print writer does not automatically flush its contents to the target file when a newline is encountered. The output to the file is buffered.
        Parameters:
        fileName - the target file's name. If the file already exists, its contents are removed, otherwise a new file is created.
        csn - the name of the character set used for character encoding.
        Throws:
        FileNotFoundException - if an error occurs while opening or creating the target file.
        NullPointerException - if csn is null.
        UnsupportedEncodingException - if the encoding specified by csn is not supported.
    • Method Detail

      • checkError

        public boolean checkError()
        Flushes this writer and returns the value of the error flag.
        Returns:
        true if either an IOException has been thrown previously or if setError() has been called; false otherwise.
        See Also:
        setError()
      • clearError

        protected void clearError()
        Sets the error state of the stream to false.
        Since:
        1.6
      • close

        public void close()
        Closes this print writer. Flushes this writer and then closes the target. If an I/O error occurs, this writer's error flag is set to true.
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in class Writer
      • flush

        public void flush()
        Ensures that all pending data is sent out to the target. It also flushes the target. If an I/O error occurs, this writer's error state is set to true.
        Specified by:
        flush in interface Flushable
        Specified by:
        flush in class Writer
      • format

        public PrintWriter format(String format,
                         Object... args)
        Formats args according to the format string format, and writes the result to this stream. This method uses the user's default locale. See "Be wary of the default locale". If automatic flushing is enabled then the buffer is flushed as well.
        Parameters:
        format - the format string (see Formatter.format(java.lang.String, java.lang.Object...))
        args - the list of arguments passed to the formatter. If there are more arguments than required by format, additional arguments are ignored.
        Returns:
        this writer.
        Throws:
        IllegalFormatException - if the format string is illegal or incompatible with the arguments, if there are not enough arguments or if any other error regarding the format string or arguments is detected.
        NullPointerException - if format == null
      • format

        public PrintWriter format(Locale l,
                         String format,
                         Object... args)
        Writes a string formatted by an intermediate Formatter to the target using the specified locale, format string and arguments. If automatic flushing is enabled then this writer is flushed.
        Parameters:
        l - the locale used in the method. No localization will be applied if l is null.
        format - the format string (see Formatter.format(java.lang.String, java.lang.Object...))
        args - the list of arguments passed to the formatter. If there are more arguments than required by format, additional arguments are ignored.
        Returns:
        this writer.
        Throws:
        IllegalFormatException - if the format string is illegal or incompatible with the arguments, if there are not enough arguments or if any other error regarding the format string or arguments is detected.
        NullPointerException - if format == null
      • printf

        public PrintWriter printf(String format,
                         Object... args)
        Prints a formatted string. The behavior of this method is the same as this writer's #format(String, Object...) method.

        The Locale used is the user's default locale. See "Be wary of the default locale".

        Parameters:
        format - the format string (see Formatter.format(java.lang.String, java.lang.Object...))
        args - the list of arguments passed to the formatter. If there are more arguments than required by format, additional arguments are ignored.
        Returns:
        this writer.
        Throws:
        IllegalFormatException - if the format string is illegal or incompatible with the arguments, if there are not enough arguments or if any other error regarding the format string or arguments is detected.
        NullPointerException - if format == null
      • printf

        public PrintWriter printf(Locale l,
                         String format,
                         Object... args)
        Prints a formatted string. The behavior of this method is the same as this writer's #format(Locale, String, Object...) method.
        Parameters:
        l - the locale used in the method. No localization will be applied if l is null.
        format - the format string (see Formatter.format(java.lang.String, java.lang.Object...))
        args - the list of arguments passed to the formatter. If there are more arguments than required by format, additional arguments are ignored.
        Returns:
        this writer.
        Throws:
        IllegalFormatException - if the format string is illegal or incompatible with the arguments, if there are not enough arguments or if any other error regarding the format string or arguments is detected.
        NullPointerException - if format == null
      • print

        public void print(char[] charArray)
        Prints the string representation of the specified character array to the target.
        Parameters:
        charArray - the character array to print to the target.
        See Also:
        print(String)
      • print

        public void print(char ch)
        Prints the string representation of the specified character to the target.
        Parameters:
        ch - the character to print to the target.
        See Also:
        print(String)
      • print

        public void print(double dnum)
        Prints the string representation of the specified double to the target.
        Parameters:
        dnum - the double value to print to the target.
        See Also:
        print(String)
      • print

        public void print(float fnum)
        Prints the string representation of the specified float to the target.
        Parameters:
        fnum - the float value to print to the target.
        See Also:
        print(String)
      • print

        public void print(int inum)
        Prints the string representation of the specified integer to the target.
        Parameters:
        inum - the integer value to print to the target.
        See Also:
        print(String)
      • print

        public void print(long lnum)
        Prints the string representation of the specified long to the target.
        Parameters:
        lnum - the long value to print to the target.
        See Also:
        print(String)
      • print

        public void print(Object obj)
        Prints the string representation of the specified object to the target.
        Parameters:
        obj - the object to print to the target.
        See Also:
        print(String)
      • print

        public void print(String str)
        Prints a string to the target. The string is converted to an array of bytes using the encoding chosen during the construction of this writer. The bytes are then written to the target with write(int).

        If an I/O error occurs, this writer's error flag is set to true.

        Parameters:
        str - the string to print to the target.
        See Also:
        write(int)
      • print

        public void print(boolean bool)
        Prints the string representation of the specified boolean to the target.
        Parameters:
        bool - the boolean value to print the target.
        See Also:
        print(String)
      • println

        public void println()
        Prints a newline. Flushes this writer if the autoFlush flag is set to true.
      • println

        public void println(char[] chars)
        Prints the string representation of the character array chars followed by a newline. Flushes this writer if the autoFlush flag is set to true.
      • println

        public void println(char c)
        Prints the string representation of the char c followed by a newline. Flushes this writer if the autoFlush flag is set to true.
      • println

        public void println(double d)
        Prints the string representation of the double d followed by a newline. Flushes this writer if the autoFlush flag is set to true.
      • println

        public void println(float f)
        Prints the string representation of the float f followed by a newline. Flushes this writer if the autoFlush flag is set to true.
      • println

        public void println(int i)
        Prints the string representation of the int i followed by a newline. Flushes this writer if the autoFlush flag is set to true.
      • println

        public void println(long l)
        Prints the string representation of the long l followed by a newline. Flushes this writer if the autoFlush flag is set to true.
      • println

        public void println(Object obj)
        Prints the string representation of the object o, or "null, followed by a newline. Flushes this writer if the autoFlush flag is set to true.
      • println

        public void println(String str)
        Prints the string representation of the string s followed by a newline. Flushes this writer if the autoFlush flag is set to true.

        The string is converted to an array of bytes using the encoding chosen during the construction of this writer. The bytes are then written to the target with write(int). Finally, this writer is flushed if the autoFlush flag is set to true.

        If an I/O error occurs, this writer's error flag is set to true.

      • println

        public void println(boolean b)
        Prints the string representation of the boolean b followed by a newline. Flushes this writer if the autoFlush flag is set to true.
      • setError

        protected void setError()
        Sets the error flag of this writer to true.
      • write

        public void write(char[] buf)
        Writes the character buffer buf to the target.
        Overrides:
        write in class Writer
        Parameters:
        buf - the non-null array containing characters to write.
      • write

        public void write(char[] buf,
                 int offset,
                 int count)
        Writes count characters from buffer starting at offset to the target.

        This writer's error flag is set to true if this writer is closed or an I/O error occurs.

        Specified by:
        write in class Writer
        Parameters:
        buf - the buffer to write to the target.
        offset - the index of the first character in buffer to write.
        count - the number of characters in buffer to write.
        Throws:
        IndexOutOfBoundsException - if offset < 0 or count < 0, or if offset + count is greater than the length of buf.
      • write

        public void write(int oneChar)
        Writes one character to the target. Only the two least significant bytes of the integer oneChar are written.

        This writer's error flag is set to true if this writer is closed or an I/O error occurs.

        Overrides:
        write in class Writer
        Parameters:
        oneChar - the character to write to the target.
      • write

        public void write(String str)
        Writes the characters from the specified string to the target.
        Overrides:
        write in class Writer
        Parameters:
        str - the non-null string containing the characters to write.
      • write

        public void write(String str,
                 int offset,
                 int count)
        Writes count characters from str starting at offset to the target.
        Overrides:
        write in class Writer
        Parameters:
        str - the non-null string containing the characters to write.
        offset - the index of the first character in str to write.
        count - the number of characters from str to write.
        Throws:
        IndexOutOfBoundsException - if offset < 0 or count < 0, or if offset + count is greater than the length of str.
      • append

        public PrintWriter append(char c)
        Appends the character c to the target.
        Specified by:
        append in interface Appendable
        Overrides:
        append in class Writer
        Parameters:
        c - the character to append to the target.
        Returns:
        this writer.
      • append

        public PrintWriter append(CharSequence csq)
        Appends the character sequence csq to the target. This method works the same way as PrintWriter.print(csq.toString()). If csq is null, then the string "null" is written to the target.
        Specified by:
        append in interface Appendable
        Overrides:
        append in class Writer
        Parameters:
        csq - the character sequence appended to the target.
        Returns:
        this writer.
      • append

        public PrintWriter append(CharSequence csq,
                         int start,
                         int end)
        Appends a subsequence of the character sequence csq to the target. This method works the same way as PrintWriter.print(csq.subsequence(start, end).toString()). If csq is null, then the specified subsequence of the string "null" will be written to the target.
        Specified by:
        append in interface Appendable
        Overrides:
        append in class Writer
        Parameters:
        csq - the character sequence appended to the target.
        start - the index of the first char in the character sequence appended to the target.
        end - the index of the character following the last character of the subsequence appended to the target.
        Returns:
        this writer.
        Throws:
        StringIndexOutOfBoundsException - if start > end, start < 0, end < 0 or either start or end are greater or equal than the length of csq.


Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 270 / . Delta: 0.04487 с