Java Text File Write writeStringToFile(String fileName, String str, boolean isAppend)

Here you can find the source of writeStringToFile(String fileName, String str, boolean isAppend)

Description

write String To File

License

Apache License

Declaration

public static void writeStringToFile(String fileName, String str, boolean isAppend) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedWriter;

import java.io.FileOutputStream;
import java.io.IOException;

import java.io.OutputStreamWriter;

public class Main {
    public static void writeStringToFile(String fileName, String str, boolean isAppend) throws IOException {
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName, isAppend)));

        try {//from   w  w w.j ava2s  .co m
            bw.write(str);
            bw.flush();
        } finally {
            bw.close();
        }
    }

    public static void writeStringToFile(String fileName, String str, String encoding, boolean isAppend)
            throws IOException {
        BufferedWriter bw = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(fileName, isAppend), encoding));

        try {
            bw.write(str);
            bw.flush();
        } finally {
            bw.close();
        }
    }
}

Related

  1. writeStringToFile(String file, String str, boolean append, boolean newLine)
  2. writeStringToFile(String fileName, String content)
  3. writeStringToFile(String filename, String content)
  4. writeStringToFile(String fileName, String src)
  5. writeStringToFile(String filename, String str)
  6. writeStringToFile(String filename, String string)
  7. writeStringToFile(String filename, String string, boolean overwrite)
  8. writeStringToFile(String filename, String stringToWrite)
  9. writeStringToFile(String filename, String text)