![]() |
VOOZH | about |
Java PrintWriter class gives Prints formatted representations of objects to a text-output stream. It implements all of the print methods found in PrintStream. It does not contain methods for writing raw bytes, for which a program should use unencoded byte streams. Unlike the PrintStream class, if automatic flushing is enabled it will be done only when one of the println, printf, or format methods is invoked, rather than whenever a newline character happens to be output.
These methods use the platform's own notion of line separator rather than the newline character.
Methods in this class never throw I/O exceptions, although some of its constructors may. The client may inquire as to whether any errors have occurred by invoking checkError().
public class PrintWriter extends Writer
Methods of PrinterWriter Class in Java are mentioned below:
| Method | Description |
|---|---|
| PrintWriter append(char c) | Appends the specified character to this writer |
| PrintWriter append(CharSequence csq, int start, int end) | Appends the specified character sequence to this writer. |
| PrintWriter append(CharSequence csq) | Appends a subsequence of the specified character sequence to this writer. |
| boolean checkError() | Flushes the stream and checks its error state. |
| protected void clearError() | Clears the internal error state of this stream. |
| void close() | Closes the stream and releases any system resources associated with it. |
| void flush() | Flushes the stream. |
| PrintWriter format(Locale l, String format, Object... args) | Writes a formatted string to this writer using the specified format string and arguments. |
| PrintWriter format(String format, Object... args) | Writes a formatted string to this writer using the specified format string and arguments. |
| void print(boolean b) | Prints a boolean value. |
| void print(char c) | Prints a character. |
| void print(char[] s) | Prints a character array. |
| void print(double d) | Prints a double. |
| void print(float f) | Prints a float. |
| void print(int i) | Prints an integer. |
| void print(long l) | Prints a long integer. |
| void print(Object obj) | Prints an object. |
| void print(String s) | Prints a string. |
Appends the specified character to this writer
Syntax :public PrintWriter append(char c) Parameters: c - The 16-bit character to append Returns: This writer
Appends the specified character sequence to this writer.
Syntax :public PrintWriter append(CharSequence csq, int start,int end) Parameters: csq - The character sequence from which a subsequence will be appended. start - The index of the first character in the subsequence end - The index of the character following the last character in the subsequence Returns:This writer Throws: IndexOutOfBoundsException
Appends a subsequence of the specified character sequence to this writer.
Syntax :public PrintWriter append(CharSequence csq) Parameters: csq - The character sequence to append. Returns: This writer
Flushes the stream and checks its error state.
Syntax :public boolean checkError() Returns: true if and only if this stream has encountered an IOException other than InterruptedIOException, or the setError method has been invoked
Clears the internal error state of this stream.
Syntax :protected void clearError()
Closes the stream and releases any system resources associated with it.
Syntax :public void close() Specified by:close in class Writer
Flushes the stream.
Syntax :public void flush() Specified by:flush in interface Flushable Specified by:flush in class Writer
Writes a formatted string to this writer using the specified format string and arguments.
Syntax :public PrintWriter format(Locale l, String format, Object... args) Parameters: l - The locale to apply during formatting. If l is null, then no localization is applied. format - A format string as described in Format string syntax args - Arguments referenced by the format specifiers in the format string. The number of arguments is variable and may be zero. Returns: This writer Throws: IllegalFormatException NullPointerException
Writes a formatted string to this writer using the specified format string and arguments.
Syntax :public PrintWriter format(String format, Object... args) Parameters: format - A format string as described in Format string syntax args - Arguments referenced by the format specifiers in the format string. The number of arguments is variable and may be zero. Returns: This writer Throws: IllegalFormatException NullPointerException
Prints a boolean value.
Syntax :public void print(boolean b)
Prints a character.
Syntax :public void print(char c)
Prints an array of characters.
Syntax :public void print(char[] s)
Prints a double-precision floating-point number.
Syntax :public void print(double b)
Prints a floating-point number.
Syntax :public void print(float f)
Prints an integer.
Syntax :public void print(int i)
Prints a long integer.
Syntax :public void print(long l)
Prints an object.
Syntax :public void print(Object obj)
Prints a string.
Syntax :public void print(String s)
Output
true14.533GeeksforGeeks java.io.PrintWriter@1540e19d Geek false This is my GeeksforGeeks program
Next Article: Java.io.PrintWriter class in Java | Set 2