Java FileWriter Write saveStringToFile(String filePath, String content, boolean isOverwrite)

Here you can find the source of saveStringToFile(String filePath, String content, boolean isOverwrite)

Description

save String To File

License

Open Source License

Declaration

public static boolean saveStringToFile(String filePath, String content, boolean isOverwrite)
            throws FileNotFoundException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.*;

public class Main {
    public static boolean saveStringToFile(String filePath, String content, boolean isOverwrite)
            throws FileNotFoundException {
        File file = new File(filePath);
        if (file.exists()) {
            if (isOverwrite) {
                //noinspection ResultOfMethodCallIgnored
                file.delete();//from w  w  w  .  j a v a 2  s .  c o m
            } 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;
    }
}

Related

  1. saveString(String location, String content)
  2. saveStringFile(String fileName, String str)
  3. saveStringInFile(String filePath, String data)
  4. saveStringToDisc(final String params, final String filePath)
  5. saveStringToFile(String content, File destFile)
  6. saveStringToFile(String fileToSave, String data)
  7. saveStringToFile(String string, String fileName)
  8. saveStringToFile(String text, File fname)
  9. saveTemporaryTermFile(File tempLocation, String word, Collection termList)