Usage of the printwriter class in Java

Source: Internet
Author: User
Tags truncated
Printwriter class: Java. Io
Printwriter class
Java. Lang. Object
Java. Io. Writer
Java. Io. printwriter
All Implemented interfaces:
Closeable, flushable, appendable
--------------------------------------------------------------------------------
Public class printwriter extends writer prints the formatted representation of the object to the text output stream. This class implements all print methods in printstream. It does not include methods used to write original bytes. For these bytes, the program should use unencoded byte streams for writing.
Unlike the printstream class, if automatic refresh is enabled, this operation can be completed only when one of the methods of println, printf, or format is called, rather than when a line break is output. These methods use the platform's own line separator concept, rather than line breaks.
Methods In this class do not throw an I/O exception, although some of its constructor methods may throw an exception. The client may query whether an error occurs when checkerror () is called.
Start with the following versions:
Jdk1.1
--------------------------------------------------------------------------------
Field Abstract
Protected writer out
The bottom layer character output stream of this printwriter.
Fields inherited from Java. Io. Writer
Lock
Constructor Summary
Printwriter (File file)
Use the specified file to create a new printwriter that does not have automatic row refresh.
Printwriter (File file, string CSN)
Creates a new printwriter that has the specified file and Character Set and does not contain automatic refresh.
Printwriter (outputstream out)
Create a new printwriter without automatic row refresh based on the existing outputstream.
Printwriter (outputstream out, Boolean autoflush)
Use the existing outputstream to create a new printwriter.
Printwriter (string filename)
Create a new printwriter with the specified file name without automatic row refresh.
Printwriter (string filename, string CSN)
Create a new printwriter with the specified file name and character set without automatic row refresh.
Printwriter (writer out)
Create a new printwriter without automatic row refresh.
Printwriter (writer out, Boolean autoflush)
Create a new printwriter.
Method Summary
Printwriter append (char C)
Add the specified character to this writer.
Printwriter append (charsequence CSQ)
Add the specified character sequence to this writer.
Printwriter append (charsequence CSQ, int start, int end)
Add the child sequence of the specified character sequence to this writer.
Boolean checkerror ()
If the stream is not closed, refresh the stream and check its error status.
Protected void clearerror ()
Clears the error status of this stream.
Void close ()
Close the stream and release all associated system resources.
Void flush ()
Refresh the buffer of the stream.
Printwriter format (locale L, string format, object... ARGs)
Write a formatted string to this writer using the specified format string and parameters.
Printwriter format (string format, object... ARGs)
Write a formatted string to this writer using the specified format string and parameters.
Void print (Boolean B)
Print the Boolean value.
Void print (char C)
Print characters.
Void print (char [] S)
Print the character array.
Void print (double D)
Print the double-precision floating point number.
Void print (float F)
Print a floating point number.
Void print (int I)
Print the integer.
Void print (long l)
Print the long integer.
Void print (Object OBJ)
Print objects.
Void print (string S)
Print the string.
Printwriter printf (locale L, string format, object... ARGs)
A convenient method to write formatted strings to this writer using specified format strings and parameters.
Printwriter printf (string format, object... ARGs)
A convenient method to write formatted strings to this writer using specified format strings and parameters.
Void println ()
Terminate the current row by writing the row separator string.
Void println (Boolean X)
Print the Boolean value and terminate the row.
Void println (char X)
Print the character and terminate the line.
Void println (char [] X)
Print the character array and terminate the row.
Void println (Double X)
Print the double-precision floating point number and terminate the row.
Void println (float X)
Print the floating point number and terminate the row.
Void println (int x)
Print the integer and terminate the row.
Void println (long X)
Print the long integer and terminate the row.
Void println (Object X)
Print the object and terminate the row.
Void println (string X)
Print the string and terminate the line.
Protected void seterror ()
Indicates that an error has occurred.
Void write (char [] BUF)
Write character arrays.
Void write (char [] Buf, int off, int Len)
Write a part of the character array.
Void write (int c)
Write a single character.
Void write (string S)
Write a string.
Void write (string S, int off, int Len)
Write a part of the string.
Methods inherited from class java. Lang. Object
Clone, equals, finalize, getclass, hashcode, notify, policyall, tostring, wait
Field details
Out
Protected writer out the bottom-layer character output stream of this printwriter.
Start with the following versions:
1.2
Constructor details
Printwriter
Public printwriter (writer out) creates a new printwriter without automatic row refresh.
Parameters:
Out-character output stream
--------------------------------------------------------------------------------
Printwriter
Public printwriter (writer out,
Boolean autoflush) to create a new printwriter.
Parameters:
Out-character output stream
Autoflush-Boolean variable; if true, the println, printf, or format method refreshes the output buffer.
--------------------------------------------------------------------------------
Printwriter
Public printwriter (outputstream out) creates a new printwriter without automatic row refresh based on the existing outputstream. This convenient constructor creates necessary intermediate outputstreamwriter, which converts characters to bytes using the default character encoding.
Parameters:
Out-output stream
For more information, see:
Outputstreamwriter. outputstreamwriter (Java. Io. outputstream)
--------------------------------------------------------------------------------
Printwriter
Public printwriter (outputstream out,
Boolean autoflush) creates a new printwriter through the existing outputstream. This convenient constructor creates necessary intermediate outputstreamwriter, which converts characters to bytes using the default character encoding.
Parameters:
Out-output stream
Autoflush-Boolean variable; if true, the println, printf, or format method refreshes the output buffer.
For more information, see:
Outputstreamwriter. outputstreamwriter (Java. Io. outputstream)
--------------------------------------------------------------------------------
Printwriter
Public printwriter (string filename)
Throws filenotfoundexception creates a new printwriter with the specified file name and without automatic row refresh. This convenient constructor creates necessary intermediate outputstreamwriter, which uses the default charset of this Java Virtual Machine instance for character encoding.
Parameters:
Filename-name of the file used as the target for this writer. If the file exists, the file size is truncated to zero. Otherwise, a new file is created. Write the output to a file and buffer it.
Throw:
Filenotfoundexception-if the specified string does not represent an existing generic file that can be written and cannot be created, or other errors occur when the file is opened or created.
Securityexception-if a security manager exists and checkwrite (filename) rejects access to the file.
Start with the following versions:
1.5
--------------------------------------------------------------------------------
Printwriter
Public printwriter (string filename,
String CSN)
Throws filenotfoundexception,
Unsupportedencodingexception creates a new printwriter with the specified file name and Character Set and without automatic row refresh. This convenient constructor creates the necessary intermediate outputstreamwriter, which uses the provided character set for character encoding.
Parameters:
Filename-name of the file used as the target for this writer. If the file exists, the file size is truncated to zero. Otherwise, a new file is created. Write the output to a file and buffer it.
CSN-names of supported character sets
Throw:
Filenotfoundexception-if the specified string does not represent an existing generic file that can be written and cannot be created, or other errors occur when the file is opened or created.
Securityexception-if the security manager exists and the checkwrite
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.