- PrintWriter is a better alternative to OutputStreamWriter and FileWriter.
- 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);