IT. Expert System.

Android Reference

PrintStream


java.io

Class PrintStream

  • All Implemented Interfaces:
    Closeable, Flushable, Appendable, AutoCloseable
    Direct Known Subclasses:
    Logger.Stream


    public class PrintStream
    extends FilterOutputStream
    implements Appendable, Closeable
    Wraps an existing OutputStream and provides convenience methods for writing common data types in a human readable format. This is not to be confused with DataOutputStream which is used for encoding common data types so that they can be read back in. No IOException is thrown by this class. Instead, callers should use checkError() to see if a problem has occurred in this stream.
    • Constructor Summary

      Constructors
      Constructor and Description
      PrintStream(File file)
      Constructs a new PrintStream with file as its target.
      PrintStream(File file, String charsetName)
      Constructs a new PrintStream with file as its target.
      PrintStream(OutputStream out)
      Constructs a new PrintStream with out as its target stream.
      PrintStream(OutputStream out, boolean autoFlush)
      Constructs a new PrintStream with out as its target stream.
      PrintStream(OutputStream out, boolean autoFlush, String charsetName)
      Constructs a new PrintStream with out as its target stream and using the character encoding charsetName while writing.
      PrintStream(String fileName)
      Constructs a new PrintStream with the file identified by fileName as its target.
      PrintStream(String fileName, String charsetName)
      Constructs a new PrintStream with the file identified by fileName as its target.
    • Method Summary

      Methods
      Modifier and Type Method and Description
      PrintStream append(char c)
      Appends the char c.
      PrintStream append(CharSequence charSequence)
      Appends the CharSequence charSequence, or "null".
      PrintStream append(CharSequence charSequence, int start, int end)
      Appends a subsequence of CharSequence charSequence, or "null".
      boolean checkError()
      Flushes this stream 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 stream.
      void flush()
      Ensures that all pending data is sent out to the target stream.
      PrintStream format(Locale l, String format, Object... args)
      Writes a string formatted by an intermediate Formatter to this stream using the specified locale, format string and arguments.
      PrintStream format(String format, Object... args)
      Formats args according to the format string format, and writes the result to this stream.
      void print(boolean b)
      Prints the string representation of the boolean b.
      void print(char c)
      Prints the string representation of the char c.
      void print(char[] chars)
      Prints the string representation of the character array chars.
      void print(double d)
      Prints the string representation of the double d.
      void print(float f)
      Prints the string representation of the float f.
      void print(int i)
      Prints the string representation of the int i.
      void print(long l)
      Prints the string representation of the long l.
      void print(Object o)
      Prints the string representation of the Object o, or "null".
      void print(String str)
      Prints a string to the target stream.
      PrintStream printf(Locale l, String format, Object... args)
      Prints a formatted string.
      PrintStream 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 o)
      Prints the string representation of the Object o, or "null", followed by a newline.
      void println(String str)
      Prints a string followed by a newline.
      protected void setError()
      Sets the error flag of this print stream to true.
      void write(byte[] buffer, int offset, int length)
      Writes count bytes from buffer starting at offset to the target stream.
      void write(int oneByte)
      Writes one byte to the target stream.
    • Constructor Detail

      • PrintStream

        public PrintStream(OutputStream out)
        Constructs a new PrintStream with out as its target stream. By default, the new print stream 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.
      • PrintStream

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

        public PrintStream(OutputStream out,
                   boolean autoFlush,
                   String charsetName)
                    throws UnsupportedEncodingException
        Constructs a new PrintStream with out as its target stream and using the character encoding charsetName while writing. The parameter autoFlush determines if the print stream automatically flushes its contents to the target stream when a newline is encountered.
        Parameters:
        out - the target output stream.
        autoFlush - indicates whether or not to flush contents upon encountering a newline sequence.
        charsetName - the non-null string describing the desired character encoding.
        Throws:
        NullPointerException - if out or charsetName are null.
        UnsupportedEncodingException - if the encoding specified by charsetName is not supported.
      • PrintStream

        public PrintStream(File file)
                    throws FileNotFoundException
        Constructs a new PrintStream with file as its target. The VM's default character set is used for character encoding.
        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.
      • PrintStream

        public PrintStream(File file,
                   String charsetName)
                    throws FileNotFoundException,
                           UnsupportedEncodingException
        Constructs a new PrintStream with file as its target. The character set named charsetName is used for character encoding.
        Parameters:
        file - the target file. If the file already exists, its contents are removed, otherwise a new file is created.
        charsetName - 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 charsetName is null.
        UnsupportedEncodingException - if the encoding specified by charsetName is not supported.
      • PrintStream

        public PrintStream(String fileName)
                    throws FileNotFoundException
        Constructs a new PrintStream with the file identified by fileName as its target. The VM's default character set is used for character encoding.
        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.
      • PrintStream

        public PrintStream(String fileName,
                   String charsetName)
                    throws FileNotFoundException,
                           UnsupportedEncodingException
        Constructs a new PrintStream with the file identified by fileName as its target. The character set named charsetName is used for character encoding.
        Parameters:
        fileName - the target file's name. If the file already exists, its contents are removed, otherwise a new file is created.
        charsetName - 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 charsetName is null.
        UnsupportedEncodingException - if the encoding specified by charsetName is not supported.
    • Method Detail

      • checkError

        public boolean checkError()
        Flushes this stream 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 stream. Flushes this stream and then closes the target stream. If an I/O error occurs, this stream's error state is set to true.
        Specified by:
        close in interface Closeable
        Specified by:
        close in interface AutoCloseable
        Overrides:
        close in class FilterOutputStream
      • flush

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

        public PrintStream 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".
        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 stream.
        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 PrintStream format(Locale l,
                         String format,
                         Object... args)
        Writes a string formatted by an intermediate Formatter to this stream using the specified locale, format string and arguments.
        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 stream.
        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 PrintStream printf(String format,
                         Object... args)
        Prints a formatted string. The behavior of this method is the same as this stream'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 stream.
        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 PrintStream printf(Locale l,
                         String format,
                         Object... args)
        Prints a formatted string. The behavior of this method is the same as this stream'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 stream.
        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[] chars)
        Prints the string representation of the character array chars.
      • print

        public void print(char c)
        Prints the string representation of the char c.
      • print

        public void print(double d)
        Prints the string representation of the double d.
      • print

        public void print(float f)
        Prints the string representation of the float f.
      • print

        public void print(int i)
        Prints the string representation of the int i.
      • print

        public void print(long l)
        Prints the string representation of the long l.
      • print

        public void print(Object o)
        Prints the string representation of the Object o, or "null".
      • print

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

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

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

        public void print(boolean b)
        Prints the string representation of the boolean b.
      • println

        public void println()
        Prints a newline.
      • println

        public void println(char[] chars)
        Prints the string representation of the character array chars followed by a newline.
      • println

        public void println(char c)
        Prints the string representation of the char c followed by a newline.
      • println

        public void println(double d)
        Prints the string representation of the double d followed by a newline.
      • println

        public void println(float f)
        Prints the string representation of the float f followed by a newline.
      • println

        public void println(int i)
        Prints the string representation of the int i followed by a newline.
      • println

        public void println(long l)
        Prints the string representation of the long l followed by a newline.
      • println

        public void println(Object o)
        Prints the string representation of the Object o, or "null", followed by a newline.
      • println

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

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

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

        public void println(boolean b)
        Prints the string representation of the boolean b followed by a newline.
      • setError

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

        public void write(byte[] buffer,
                 int offset,
                 int length)
        Writes count bytes from buffer starting at offset to the target stream. If autoFlush is set, this stream gets flushed after writing the buffer.

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

        Overrides:
        write in class FilterOutputStream
        Parameters:
        buffer - the buffer to be written.
        offset - the index of the first byte in buffer to write.
        length - the number of bytes in buffer to write.
        Throws:
        IndexOutOfBoundsException - if offset < 0 or count < 0, or if offset + count is bigger than the length of buffer.
        See Also:
        flush()
      • write

        public void write(int oneByte)
        Writes one byte to the target stream. Only the least significant byte of the integer oneByte is written. This stream is flushed if oneByte is equal to the character '\n' and this stream is set to autoFlush.

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

        Overrides:
        write in class FilterOutputStream
        Parameters:
        oneByte - the byte to be written
      • append

        public PrintStream append(char c)
        Appends the char c.
        Specified by:
        append in interface Appendable
        Parameters:
        c - the character to append.
        Returns:
        this stream.
      • append

        public PrintStream append(CharSequence charSequence)
        Appends the CharSequence charSequence, or "null".
        Specified by:
        append in interface Appendable
        Parameters:
        charSequence - the character sequence to append.
        Returns:
        this stream.
      • append

        public PrintStream append(CharSequence charSequence,
                         int start,
                         int end)
        Appends a subsequence of CharSequence charSequence, or "null".
        Specified by:
        append in interface Appendable
        Parameters:
        charSequence - the character sequence appended to the target stream.
        start - the index of the first char in the character sequence appended to the target stream.
        end - the index of the character following the last character of the subsequence appended to the target stream.
        Returns:
        this stream.
        Throws:
        IndexOutOfBoundsException - if start > end, start < 0, end < 0 or either start or end are greater or equal than the length of charSequence.


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: 285 / 158670513. Delta: 0.04546 с