Java Utililty Methods PrintWriter Write

List of utility methods to do PrintWriter Write

Description

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

Method

booleansaveStringAsFile(String string, String path)
save String As File
PrintWriter out;
try {
    out = new PrintWriter(path);
    out.println(string);
    out.close();
} catch (FileNotFoundException e) {
    e.printStackTrace();
    return false;
...
voidsaveStringBufferTofile(String fileName, StringBuffer sb)
save String Buffer Tofile
PrintWriter writer = new PrintWriter(fileName, "UTF-8");
try {
    writer.println(sb);
    writer.close();
} finally {
    writer.close();
voidsaveStrings(final String filename, final String[] sArray)
Saves string arrays to files (the assumption being that said file is a collection/list of arbitrary strings in a particular layout
try {
    final File file = new File(filename);
    final PrintWriter output = new PrintWriter(file);
    for (final String s : sArray) {
        output.println(s);
    output.close();
} catch (Exception e) {
...
voidsaveStrings(String filename, String data[])
( begin auto-generated from saveStrings.xml ) Writes an array of strings to a file, one line per string.
saveStrings(saveFile(filename), data);
voidsaveStrings(String theFilePath, String[] theStrings)
save Strings
createPath(theFilePath);
saveStrings(getOutputStream(theFilePath), theStrings);
voidsaveStringToFile(String text, String path)
save String To File
PrintWriter writer = null;
try {
    writer = new PrintWriter(path, "UTF-8");
} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (UnsupportedEncodingException e) {
    e.printStackTrace();
writer.write(text);
writer.close();
voidsaveToFile(String buf, String fileName)
save To File
try (PrintWriter out = new PrintWriter(fileName)) {
    out.println(buf);
} catch (Exception e) {
    throw new RuntimeException("Failed to write content to file " + fileName, e);
voidsaveToFile(String path, String data)
save To File
try (PrintWriter writer = new PrintWriter(path)) {
    writer.println(data);