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

voidsaveFile(File file, String contents)
Save the given contents into the given file.
BufferedWriter writer = null;
try {
    writer = new BufferedWriter(new FileWriter(file));
    writer.write(contents);
    writer.flush();
} finally {
    if (writer != null) {
        try {
...
voidsaveFile(File file, String data)
Saves the String data to the File.
FileWriter writer = null;
try {
    writer = new FileWriter(file);
    writer.write(data);
} catch (IOException e) {
    throw e;
} finally {
    writer.close();
...
voidsaveFile(File file, String fileContent)
save File
if (file != null) {
    try {
        FileWriter fstream = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fstream);
        out.write(fileContent);
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
...
voidsaveFile(File file, String text, boolean append)
save File
if (file.isDirectory()) {
    throw new IOException(file + ": Is a directory");
} else if (file.isFile()) {
    FileWriter fileWriter;
    if (append)
        fileWriter = new FileWriter(file, true);
    else
        fileWriter = new FileWriter(file, false);
...
voidsaveFile(List contents, String fileName)
save File
File file = new File(fileName);
saveFile(contents, file);
voidsaveFile(String filePath, String content)
Saves the supplied content to the specified file path.
FileWriter fw = new FileWriter(new File(filePath));
fw.write(content);
fw.close();
booleansaveFile(String filePath, String data)
save File
return writeToFile(filePath, data, false);
voidsaveFile(String path, Map> setup)
Save file of settings when given the correct format of settings.
PrintWriter p = new PrintWriter(new FileWriter(path), true);
for (String heading : setup.keySet()) {
    p.println("[" + heading + "]");
    for (String key : setup.get(heading).keySet()) {
        p.println(key + "=" + setup.get(heading).get(key));
    p.println("");
p.close();
voidsaveFile(String path, String content)
save File
File f = new File(path);
if (!f.exists()) {
    f.createNewFile();
FileWriter fstream = null;
BufferedWriter out = null;
try {
    fstream = new FileWriter(path);
...
FileSaveFile(String path, String data, boolean deleteOnExit)
Save File
File f = new File(path);
if (deleteOnExit) {
    f.deleteOnExit();
BufferedWriter out = new BufferedWriter(new FileWriter(f));
out.write(data);
out.close();
return f;
...