.PrintWriter Class - Tutorialspoint
Maybe your like
- Java.io - Home
- Java.io - BufferedInputStream
- Java.io - BufferedOutputStream
- Java.io - BufferedReader
- Java.io - BufferedWriter
- Java.io - ByteArrayInputStream
- Java.io - ByteArrayOutputStream
- Java.io - CharArrayReader
- Java.io - CharArrayWriter
- Java.io - Console
- Java.io - DataInputStream
- Java.io - DataOutputStream
- Java.io - File
- Java.io - FileDescriptor
- Java.io - FileInputStream
- Java.io - FileOutputStream
- Java.io - FilePermission
- Java.io - FileReader
- Java.io - FileWriter
- Java.io - FilterInputStream
- Java.io - FilterOutputStream
- Java.io - FilterReader
- Java.io - FilterWriter
- Java.io - InputStream
- Java.io - InputStreamReader
- Java.io - LineNumberInputStream
- Java.io - LineNumberReader
- Java.io - ObjectInputStream
- Java.io - ObjectInputStream.GetField
- Java.io - ObjectOutputStream
- io - ObjectOutputStream.PutField
- Java.io - ObjectStreamClass
- Java.io - ObjectStreamField
- Java.io - OutputStream
- Java.io - OutputStreamWriter
- Java.io - PipedInputStream
- Java.io - PipedOutputStream
- Java.io - PipedReader
- Java.io - PipedWriter
- Java.io - PrintStream
- Java.io - PrintWriter
- Java.io - PushbackInputStream
- Java.io - PushbackReader
- Java.io - RandomAccessFile
- Java.io - Reader
- Java.io - SequenceInputStream
- Java.io - SerializablePermission
- Java.io - StreamTokenizer
- Java.io - StringBufferInputStream
- Java.io - StringReader
- Java.io - StringWriter
- Java.io - Writer
- Java.io - Interfaces
- Java.io - Exceptions
- Java.io package Useful Resources
- Java.io - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- AI Based Resume Builder
- Personal AI Study Assistant
- Generate Coding Logic
- HR Interview Questions
- Computer Glossary
- Who is Who
Introduction
The Java.io.PrintWriter class prints formatted representations of objects to a text-output stream.
Class declaration
Following is the declaration for Java.io.PrintWriter class −
public class PrintWriter extends WriterField
Following are the fields for Java.io.PrintWriter class −
protected Writer out − This is the character-output stream of this PrintWriter.
protected Object lock − This is the object used to synchronize operations on this stream.
Class constructors
| Sr.No. | Constructor & Description |
|---|---|
| 1 | PrintWriter(File file) This creates a new PrintWriter, without automatic line flushing, with the specified file. |
| 2 | PrintWriter(File file, String csn) This creates a new PrintWriter, without automatic line flushing, with the specified file and charset. |
| 3 | PrintWriter(OutputStream out) This creates a new PrintWriter, without automatic line flushing, from an existing OutputStream. |
| 4 | PrintWriter(OutputStream out, boolean autoFlush) This creates a new PrintWriter from an existing OutputStream. |
| 5 | PrintWriter(String fileName) This creates a new PrintWriter, without automatic line flushing, with the specified file name. |
| 6 | PrintWriter(String fileName, String csn) This creates a new PrintWriter, without automatic line flushing, with the specified file name and charset. |
| 7 | PrintWriter(Writer out) This creates a new PrintWriter, without automatic line flushing. |
| 8 | PrintWriter(Writer out, boolean autoFlush) This creates a new PrintWriter. |
Class methods
| Sr.No. | Method & Description |
|---|---|
| 1 | PrintWriter append(char c) This method appends the specified character to this writer. |
| 2 | PrintWriter append(CharSequence csq) This method appends the specified character sequence to this writer. |
| 3 | PrintWriter append(CharSequence csq, int start, int end) This method appends a subsequence of the specified character sequence to this writer. |
| 4 | boolean checkError() This method flushes the stream if it's not closed and checks its error state. |
| 5 | protected void clearError() This method Clears the error state of this stream. |
| 6 | void close() This method Closes the stream and releases any system resources associated with it. |
| 7 | void flush() This method Flushes the stream. |
| 8 | PrintWriter format(Locale l, String format, Object... args) This method writes a formatted string to this writer using the specified format string and arguments. |
| 9 | PrintWriter format(String format, Object... args) This method writes a formatted string to this writer using the specified format string and arguments. |
| 10 | void print(boolean b) This method prints a boolean value. |
| 11 | void print(char c) This method prints a character. |
| 12 | void print(char[] s) This method Prints an array of characters. |
| 13 | void print(double d) This method Prints a double-precision floating-point number. |
| 14 | void print(float f) This method prints a floating-point number. |
| 15 | void print(int i) This method prints an integer. |
| 16 | void print(long l) This method prints a long integer. |
| 17 | void print(Object obj) This method prints an object. |
| 18 | void print(String s) This method prints a string. |
| 19 | PrintWriter printf(Locale l, String format, Object... args) This is a convenience method to write a formatted string to this writer using the specified format string and arguments. |
| 20 | PrintWriter printf(String format, Object... args) This is a convenience method to write a formatted string to this writer using the specified format string and arguments. |
| 21 | void println() This method terminates the current line by writing the line separator string. |
| 22 | void println(boolean x) This method prints a boolean value and then terminates the line. |
| 23 | void println(char x) This method prints a character and then terminates the line. |
| 24 | void println(char[] x) This method prints an array of characters and then terminates the line. |
| 25 | void println(double x) This method prints a double-precision floating-point number and then terminates the line. |
| 26 | void println(float x) This method prints a floating-point number and then terminates the line. |
| 27 | void println(int x) This method prints an integer and then terminates the line. |
| 28 | void println(long x) This method prints a long integer and then terminates the line. |
| 29 | void println(Object x) This method prints an Object and then terminates the line. |
| 30 | void println(String x) This method prints a String and then terminates the line. |
| 31 | protected void setError() This method indicates that an error has occurred. |
| 32 | void write(char[] buf) This method writes an array of characters. |
| 33 | void write(char[] buf, int off, int len) This method writes a portion of an array of characters. |
| 34 | void write(int c) This methodWrites a single character. |
| 35 | void write(String s) This method writes a string. |
| 36 | void write(String s, int off, int len) This method writes a portion of a string. |
Methods inherited
This class inherits methods from the following classes −
- Java.io.Object
Tag » What Is Printwriter In Java
-
Java PrintWriter Class - CodeGym
-
Java PrintWriter Class - Javatpoint
-
PrintWriter (Java Platform SE 8 ) - Oracle Help Center
-
Java IO: PrintWriter
-
Java PrintWriter (With Examples) - Programiz
-
[Java] Java PrintWriter 출력 스트림에 대하여 알아보기.
-
.PrintWriter Class In Java | Set 1 - GeeksforGeeks
-
PrintWriter
-
Constructor, Methods And Examples Of Java PrintWriter - EduCBA
-
.PrintWriter Class Example - Edureka
-
Java PrintWriter With Example - DZone
-
What Is PrintWriter In Java? | Java IO | Java Tutorial - YouTube
-
Why Need PrintWriter? - Java - Stack Overflow
-
Java PrintWriter Explained With Examples (Java 9+) - CodeAhoy