Java Utililty Methods FileWriter Write

List of utility methods to do FileWriter Write

Description

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

Method

voidsaveStringInFile(String filePath, String data)
save String In File
FileWriter file = new FileWriter(filePath);
try {
    file.write(data);
} finally {
    file.close();
voidsaveStringToDisc(final String params, final String filePath)
save String To Disc
FileWriter fileWriter = null;
try {
    fileWriter = new FileWriter(new File(filePath));
    fileWriter.write(params);
} finally {
    if (fileWriter != null) {
        fileWriter.close();
voidsaveStringToFile(String content, File destFile)
save String To File
FileWriter writer = new FileWriter(destFile);
writer.write(content);
writer.close();
booleansaveStringToFile(String filePath, String content, boolean isOverwrite)
save String To File
File file = new File(filePath);
if (file.exists()) {
    if (isOverwrite) {
        file.delete();
    } else {
        return false;
boolean saved = false;
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file))) {
    bufferedWriter.write(content);
    saved = true;
} catch (IOException e1) {
    e1.printStackTrace();
return saved;
booleansaveStringToFile(String fileToSave, String data)
save String To File
Writer fw = null;
try {
    fw = new FileWriter(fileToSave);
    fw.write(data);
    fw.append('\n');
} catch (IOException e) {
    e.printStackTrace();
    return false;
...
voidsaveStringToFile(String string, String fileName)
save String To File
BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
out.append(string);
out.close();
voidsaveStringToFile(String text, File fname)
save String To File
try {
    mylogger.log(Level.INFO, "Loading: [{0}] ->file: [{1}]",
            new Object[] { text, fname.getAbsolutePath() });
    FileWriter fr = new FileWriter(fname);
    fr.write(text);
    fr.close();
} catch (IOException ex) {
    mylogger.log(Level.SEVERE, "Error while loading: ", ex);
...
voidsaveTemporaryTermFile(File tempLocation, String word, Collection termList)
Save temporary term file.
if (word == null)
    return;
if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
    if (Arrays.asList("con", "prn").contains(word))
        return;
if (!tempLocation.exists())
    tempLocation.mkdirs();
...
voidsaveText(java.io.File f, String text)
Saves 'text' to file 'f'.
java.io.StringReader in = new java.io.StringReader(text);
try {
    copyRW(in, new java.io.FileWriter(f)).close();
} catch (java.io.IOException e) {
voidsaveTextFile(File file, String text)
Change the contents of text file in its entirety, overwriting any existing text.
if (file == null) {
    throw new IllegalArgumentException("File should not be null.");
if (file.exists() && file.isDirectory()) {
    throw new IllegalArgumentException("Should not be a directory: " + file);
if (file.exists() && !file.canWrite()) {
Writer output = new BufferedWriter(new FileWriter(file));
try {
    output.write(text);
} finally {
    output.close();