PrintWriter : PrintWriter « File « Java Tutorial






  1. PrintWriter is a better alternative to OutputStreamWriter and FileWriter.
  2. PrintWriter allows you to choose an encoding by passing the encoding information to one of its constructors.
public PrintWriter (File file)
public PrintWriter (File file, String characterSet)
public PrintWriter (String filepath)
public PrintWriter (String filepath, String ccharacterSet)
public PrintWriter (OutputStream out)
public PrintWriter (Writer out)

It is easier to construct a PrintWriter than an OutputStreamWriter.

OutputStreamWriter writer = new OutputStreamWriter ( new FileOutputStream (filePath), encoding);

can be replaced by this shorter one.

PrintWriter writer = new PrintWriter (filePath, encoding);








11.34.PrintWriter
11.34.1.PrintWriter
11.34.2.PrintWriter is more convenient to work with than OutputStreamWriter
11.34.3.Write lines of text to file using a PrintWriter
11.34.4.Using PrintWriter
11.34.5.A PrintWriter that ends lines with a carriage return-line feed (CRLF).
11.34.6.A PrintWriter that also sends its output to a log stream
11.34.7.Turn System.out into a PrintWriter.