PrintWriter Class in Java

PrintWriter Class

The PrintWriter class provides better performance in comparison to OutputStreamWriter and FileWriter. It is used to print formatted representation of object to a output stream. The method of this class never throws IOException.

PrintWriter Constructors

ConstructorsDescription
PrintWriter (File file)Creates a new PrintWriter with the specified line and without automatic line flushing.
PrintWriter (File file, String csn)It constructs a PrintWriter with the specified file and charset, without auto line flusing.
PrintWriter (OutputStream out)Creates a PrintWriter from an existing OutputStream.
PrintWriter (OutputStream out, boolean autoFlush)Creates a PrintWriter from an existing OutputStream with automatic line flushing.
PrintWriter(String filename)Constructs the PrintWriter with specified file name, without auto line flushing.
PrintWriter(String filename, String csn)Creates a PrintWriter with the specified file name and charset, without auto line flushing.
PrintWriter(Writer out)Creates a PrintWriter, without auto line flushing.
PrintWriter(Writer out, boolean autoFlush)Creates a new PrintWriter with automatic line flushing.