Java Utililty Methods PrintWriter Create

List of utility methods to do PrintWriter Create

Description

The list of methods to do PrintWriter Create are organized into topic(s).

Method

PrintWritergetPrintWriter(File f)
Get a PrintWriter for the specified file, throw RuntimeExcpetion if any problems.
try {
    return new PrintWriter(new FileOutputStream(f));
} catch (Exception ex) {
    throw new RuntimeException(ex);
PrintWritergetPrintWriter(File file)
get Print Writer
Writer osWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"), 16384);
PrintWriter pw = new PrintWriter(osWriter, false);
return pw;
PrintWritergetPrintWriter(File file)
Init.
if (file.getName().endsWith(".gz")) {
    return new PrintWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(file))));
return new PrintWriter(file);
PrintWritergetPrintwriter(File file, boolean append)
Return print writer for file with UTF8 encoding.
OutputStream os = new FileOutputStream(file, append);
if (file.getName().endsWith(".gz")) {
    os = new GZIPOutputStream(os);
return new PrintWriter(new OutputStreamWriter(os, "UTF8"));
PrintWritergetPrintWriter(final File aFile, final boolean append)
get Print Writer
final FileWriter resFileOut = new FileWriter(aFile, append);
PrintWriter ret = new PrintWriter(resFileOut);
return ret;
PrintWritergetPrintWriter(String filename)
getPrintWriter
if (filename == "") {
    return null;
if (filename.equals("-")) {
    return new PrintWriter(System.out);
File outputFile = new File(filename);
if (outputFile.exists() && !outputFile.canWrite()) {
...
PrintWritergetPrintWriter(String fileName, Writer out)
get Print Writer
if (fileName == null)
    return null;
Writer writer = fileName.equals("-") ? out : new BufferedWriter(new FileWriter(fileName));
return new PrintWriter(writer);
PrintWritergetPrintWriter(String nombreFichero)
get Print Writer
PrintWriter printWriter;
FileWriter fileWriter;
fileWriter = new FileWriter(nombreFichero);
printWriter = new PrintWriter(fileWriter);
return printWriter;
PrintWritergetPrintWriter(String path, String charset, boolean isAppend)
get Print Writer
return new PrintWriter(getBufferedWriter(path, charset, isAppend));